利用源码编译Android系统的APK和可执行命令的方法
编译Android系统APK
1、设置环境
exportANDROID_HOME=/home/administrator/soft/android exportPATH=$PATH:$ANDROID_HOME/out/host/linux-x86/bin exportANDROID_PRODUCT_OUT=$ANDROID_HOME/out/target/product/generic
2、创建项目
androidcreateproject-t1-kcom.lhw.led-aMainActivity-p./led Avdid:1,It'sgetbycommand"androidlist" ProjectName:led Package:com.lhw.led MainActivity:MainActivity ProjectPath:./
接下来就是自己编写Android程序了。
3、编写Android.mk
Android.mk需要放在项目根路径下,即led下,内容:
LOCAL_PATH:=$(callmy-dir) include$(CLEAR_VARS) LOCAL_SRC_FILES:=$(callall-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
#include<stdio.h> intmain(intargc,char**argv) { printf("Thisismycommand!\n"); return0; }
2、编写Android.mk文件
LOCAL_PATH:=$(callmy-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