编译Android系统APK
1、设置环境
export ANDROID_HOME=/home/administrator/soft/android export PATH=$PATH:$ANDROID_HOME/out/host/linux-x86/bin export ANDROID_PRODUCT_OUT=$ANDROID_HOME/out/target/product/generic
2、创建项目
android create project -t 1 -k com.lhw.led -a MainActivity -p ./led Avd id: 1,It's get by command "android list" Project Name: led Package: com.lhw.led Main Activity:MainActivity Project Path: ./
接下来就是自己编写Android程序了。
3、编写Android.mk
Android.mk需要放在项目根路径下,即led下,内容:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := led LOCAL_JAVA_LIBRARIES := LOCAL_STATIC_JAVA_LIBRARIES := include $(BUILD_PACKAGE)
4、编译
在Android源码目录下执行:
./build/envsetup.sh mmm /home/administrator/workspace/android_test/led/
执行结果:
Install: out/target/product/generic/system/app/led.apk
编译Android系统可执行命令
Android系统允许开发者,自己编写"ls"这样的命令放到Android系统中。
1、编写C文件:mycmd.c
#includeint main(int argc, char **argv) { printf("This is my command!\n"); return 0; }
2、编写Android.mk文件
LOCAL_PATH := $(call my-dir) LOCAL_SRC_FILES := mycmd.c LOCAL_MODULE := mycmd LOCAL_MODULE_TAGS := mycmd LOCAL_SHARED_LIBRARIES := libc LOCAL_STATIC_LIBRARIES := include $(BUILD_EXECUTABLE)
3、编译
mmm /home/administrator/workspace/android_test/mycmd/
编译完成后信息:
Install: out/target/product/generic/system/bin/mycmd