1 在工程该目录新建 Android.mk 文件
2 给 LOCAL_PACKAGE_NAME 属性赋值用于指定工程的项目名
3 给 LOCAL_SRC_FILES 属性赋值用于指定Java文件的路径,支持同时指定多个路径
4 给 LOCAL_MANIFEST_FILE 属性赋值执行 AndroidManifest.xml 文件
5 给 LOCAL_RESOURCE_DIR 属性赋值指定资源文件所在目录,支持同时指定多个路径(如果需要同时指定多个资源目录需要给 LOCAL_AAPT_FLAGS 属性加上 --auto-add-overlay 参数)
6 给 LOCAL_PROGUARD_FLAG_FILES 属性赋值指定代码混淆的规则文件,如果不想代码进行代码混淆将 LOCAL_PROGUARD_ENABLED 属性赋值为 disabled 即可关闭代码混淆
7 引入第三方库(注意:某些库会使用一些gradle编译插件在编译时自动生成代码,这类库不支持Android.mk编译,需要去掉)
1) Gradle 依赖的第三方库默认会自动下载到 ~/.gradle 目录中,到该目录中拷贝到对应的库
2) 在 Android.mk 文件的末尾加上如下示例将第三方库添加的编译时的静态库中
include $(CLEAR_VARS)
# 在此处给 LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES 属性赋值,给三方库包指定模块名和路径,如下所示
# 注意,给第三方库定义的模块名不能和已有的模块名一致,否则编译时会包模块已被定义的错误
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := rxjava2:app/libs/rxjava2.jar
include $(BUILD_MULTI_PREBUILT)
3 如果第三方库是 jar 包则给 LOCAL_STATIC_JAVA_LIBRARIES 属性赋值,将自定义的第三方库的模块名赋值给该属性
4 如果第三方库是 aar 包则给 LOCAL_STATIC_JAVA_AAR_LIBRARIES 属性赋值,将自定义的的第三方库的模块名赋值给该属性
5 如果第三方库的 aar 包中含义资源需要给 LOCAL_AAPT_FLAGS 属性加上 --extra-packages <第三方库包名> 参数将第三方库的 R 文件添加进来
具体可参考下面的示例:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := SoundEffect
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main)
LOCAL_SRC_FILES += $(call all-java-files-under, x8utils/src/main)
LOCAL_JAVA_LIBRARIES := flyaudio
ifeq ($(ANDROID_ATC_SDK), mtk)
LOCAL_JAVA_LIBRARIES += mediatek-framework
else
LOCAL_JAVA_LIBRARIES += autochips
endif
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res/comm
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/main
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/sound
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/equalizer
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/attenuator
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/mute_level
# LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/rear_speaker
# LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/subwoofer
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/speaker_volume
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/eq_filter
# LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/subwoofer_settings
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/listen_position
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/time_calibration
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/speaker_mode
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res/test
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/x8utils/src/main/res
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
# LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PROGUARD_ENABLED := disabled
ifeq ($(TARGET_BUILD_APPS),)
LOCAL_RESOURCE_DIR += frameworks/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += frameworks/support/v7/recyclerview/res
else
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/recyclerview/res
endif
LOCAL_STATIC_JAVA_LIBRARIES := android-common
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-recyclerview
LOCAL_STATIC_JAVA_LIBRARIES += soundeffect-rxjava2
LOCAL_STATIC_JAVA_LIBRARIES += soundeffect-reactive-streams
LOCAL_STATIC_JAVA_AAR_LIBRARIES := soundeffect-rxandroid
LOCAL_STATIC_JAVA_AAR_LIBRARIES += soundeffect-rxbus2
LOCAL_AAPT_FLAGS += --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.recyclerview
LOCAL_AAPT_FLAGS += --extra-packages com.x8
# Use the following to generate versionName.
ifeq ($(shell test -f $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE) && echo yes), yes)
VERSION_CODE_LINE := $(shell grep -r "^\s*android:versionCode=\"[0-9]\+\"" $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE))
VERSION_CODE_LINE := $(shell versionCodeLine='$(VERSION_CODE_LINE)'; echo $${versionCodeLine//>/})
VERSION_CODE := $(shell expr '$(VERSION_CODE_LINE)' : "android:versionCode=\"\([0-9]\+\)\"")
ifeq ($(shell [[ "$(VERSION_CODE)" =~ [1-9][0-9]* ]] && echo yes), yes)
VERSION_NAME := $(shell \
versionName= ; \
for((i=1; i<=10000; i*=100)); do \
if [ $${i} -lt 10000 ]; then \
let tmp=$(VERSION_CODE)%\($${i}*100\)/$${i}; \
else \
let tmp=$(VERSION_CODE)/$${i}; \
fi; \
[ $${tmp} -lt 10 ] && tmp=0$${tmp}; \
[ $${i} -lt 10000 ] && tmp=.$${tmp}; \
versionName=$${tmp}$${versionName}; \
done; \
if [ -d $(LOCAL_PATH)/.git ]; then \
cd $(LOCAL_PATH); \
commitId=$$( git log --oneline | awk "NR==1"'{ gsub(/"/,""); print $$1 }' ); \
[[ $${commitId} =~ ^[0-9a-f]{7}$$ ]] && versionName=$${versionName}-$${commitId}; \
fi; \
echo $${versionName}; \
)
LOCAL_AAPT_FLAGS += --version-code $(VERSION_CODE)
LOCAL_AAPT_FLAGS += --version-name $(VERSION_NAME)
endif
endif
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := soundeffect-rxjava2:app/libs/rxjava2.jar
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += soundeffect-reactive-streams:app/libs/reactive-streams.jar
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += soundeffect-rxandroid:app/aars/rxandroid.aar
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += soundeffect-rxbus2:app/aars/rxbus2.aar
include $(BUILD_MULTI_PREBUILT)