源码树中添加app应用
Eclipse,AndroidStudio编译通过的app应用添加到Android源码中编译,需要在app工程中添加Android.mk文件。
常见Android.mk文件写法有如下三种方法:
1. 不带jni本地代码
(1)HelloWorld目录下面新建Android.mk文件
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := HelloWorld
include $(BUILD_PACKAGE)
LOCAL_MODULE_TAGS的备选值有user,eng,tests,optional,本示例中使用的TAGS值为eng,因此,仅当用户指定的编译选项为eng时才会编译该工程
(2) 配置makefile,添加新的项目
选择 /device/<company>/ <product>/xxxx.mk
在其中的PRODUCT_PACKAGES
参数列表中添加本工程:
PRODUCT_PACKAGES := \
DeskClock \
Calculator \
Calendar \
Camera2 \
Email \
HelloWorld
(3) 编译模块
在HelloWorld目录下输入mm -B -j
命令,或者切换到Android源码根目录下执行下面任意一条命令即可:
$ make HelloWorld
$ mmm ``package``/apps/HelloWorld
2. 含有jni本地代码
对于含有jni的项目,则需要修改上述新建的Android.mk,如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := HelloWorld
LOCAL_JNI_SHARED_LIBRARIES := libmynative
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
jni目录下的Android.mk如下(假设jni目录下有inc和src目录):
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmynative
LOCAL_SRC_FILES := src/mynative.c
LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/inc
include $(BUILD_SHARED_LIBRARY)
3. 含有jni本地代码,并且本地代码依赖第三方库(.a或者so)
假设本地代码依赖的第三方库为:encoder.a 和 decoder.so
(1) 修改上述jni目录下的Android,mk,添加如下两项:
LOCAL_STATIC_LIBRARIES := libencoder
LOCAL_SHARED_LIBRARIES := libdecoder
(2) 修改HelloWorld目录下的Android.mk文件
首先把 encoder.a 和 decoder.so 都拷贝到工程根目录下,然后修改Android.mk文件,添加如下两项即可:
include $(CLEAR_VARS)
LOCAL_MODULE := libencoder
LOCAL_SRC_FILES := encoder.a
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libdecoder
LOCAL_SRC_FILES := decoder.so
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(BUILD_PREBUILT)
jni: 接口(Java Native Interface)