Android的APK源代码在Android系统源代码下的编译方法
1.原因
如果你写了一个APK程序, 并且使用了第三方JAR数据包, 想把源代码放到Android系统源代码下编译, 请尝试以下过程.
2.过程
A. 将源代码复制到目录X:\Android\packages\apps\MyApp
B. 在MyApp目录下创建Android.mk文件, 内容如下:
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(callall-java-files-under, src) # Added for source code compilestart 为jar起一个别名LOCAL_STATIC_JAVA_LIBRARIES:= 3rdpartlib1 3rdpartlib2 3rdpartlib33rdpartlib4LOCAL_PACKAGE_NAME := MyApp# Added for source code compileend # LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) # Added for source code compilestart 冒号前面为jar别名,后面为jar文件的实际路径include $(CLEAR_VARS)LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES:= 3rdpartlib1:jars/org.apache.commons.codec-1.7.0.jar 3rdpartlib2:jars/org.knopflerfish.bundle.kxml-LIB-2.3.0.jar3rdpartlib3:jars/osgi.cmpn-4.3.0.jar 3rdpartlib4:jars/osgi.core-4.3.0.jarinclude $(BUILD_MULTI_PREBUILT)# Added for source code compileend # Use the folloing include to makeour test apk.include $(callall-makefiles-under,$(LOCAL_PATH))C. 回到Android系统源码目录下, 执行source/build/envsetup.h, 将会产生很多新的命令, 如mmm
D. 执行mmm packages/apps/MyApp
E. 最后生成的APK文件位置在:
X:\Android\out\target\product\rk30sdk\system\app
3.其他
mm: Builds all of the modules in the current directory.
mmm: Builds all of the modules in the supplied directories.
4.关于drawable
使用mmm编译方法编译自己apk时,没有将drawable的所有资源都编译到apk中,可以在 androidsrc/build/target/product/generic.mk文件末尾增加以下最后一句:
1 # Overrides 2 PRODUCT_BRAND := generic 3 PRODUCT_DEVICE := generic 4 PRODUCT_NAME := generic 5 PRODUCT_LOCALES += xhdpi hdpimdpi ldpi