有时候我们需要在源码环境中增加自己的应用或模块,随ROM一起发布。
下面讲述相关步骤:
1. 首先可以在SDK环境下进行编码设计(如果你的APP不涉及到emulator无法模拟的硬件的话)
也可以参考另一篇文章,直接在Eclipse中调试系统级应用源代码:
2. 在SDK环境基本调试OK
3. 将源代码复制到 $Android_Src/packages/apps/目录下,假设你的模块为 MyApplication
4. 在MyApplication目录下新建一个Android.mk文件,可以从android自带的App下复制过来修改,如Calculator2下面的Android.mk,CleanSpec.mk也一并复制过来
5. 修改Android.mk:
- LOCAL_PATH := $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_MODULE_TAGS := optional
- #import gson lib
- LOCAL_STATIC_JAVA_LIBRARIES := libgson
- LOCAL_SRC_FILES := $(call all-java-files-under, src)
- LOCAL_SDK_VERSION := current
- LOCAL_PACKAGE_NAME := MyApplication
- include $(BUILD_PACKAGE)
- ##################################################
- include $(CLEAR_VARS)
- #Add gson support
- LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libgson:libs/gson-2.2.2.jar
- include $(BUILD_MULTI_PREBUILT)
- # Use the folloing include to make our test apk.
- include $(call all-makefiles-under,$(LOCAL_PATH))
6. 修改 $Android_Src/build/target/product/common.mk
- #andy@2012.9.19,same as LOCAL_PACKAGE_NAME defined in Android.mk
- PRODUCT_PACKAGES += MyApplication
- #add before this line
- $(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
. /build/envsetup.sh
mmm packages/apps/MyApplication
make snod
或全编译
生成的apk在 out/target/product/相关目录下,跟具体的项目相关
在ROM中会在/system/app下
FAQ:
Q:编译时出现android lasses-full-debug.jar] Error 41
A:将该模块目录下的gen和bin目录删除后编译
基于第三方apk内置到ROM参考另外一篇文章: