android.mk引用aar

先看看引入jar (因为和引用aar很像)

LOCAL_STATIC_JAVA_LIBRARIES := dictenginelib \
                               org.apache.http.legacy \
                               constraint-layout-solver-1.1.3_ \
                               yxp_support-new-v4-annotations-25.3.1 \
                               yxp_support-new-v4-compat-25.3.1 \
                               yxp_support-new-v4-core-ui-25.3.1 \
                               yxp_support-new-v4-fragment-25.3.1 \
                               yxp_support-new-v4-media-compat-25.3.1 \
                               yxp_support-new-v4-core-utils-25.3.1 \
                               yxp_support-new-vector-drawable-25.3.1 \
                               yxp_support-new-animated-vector-drawable-25.3.1 \
                               IntelligentLearningScheme_cupboard-2.2.0 \
                               IntelligentLearningScheme_glide-4.3.1 \
                               IntelligentLearningScheme_glide_annotations-4.3.1 \
                               IntelligentLearningScheme_glide_disklrucache-4.3.1 \
                               IntelligentLearningScheme_glide_gifdecoder-4.3.1\
                               IntelligentLearningScheme_gson-2.8.5 \
                               IntelligentLearningScheme_okgo-3.0.4 \
                               IntelligentLearningScheme_okhttp-3.8.1 \
                               IntelligentLearningScheme_okio-1.13.0

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := IntelligentLearningScheme_cupboard-2.2.0:libs/cupboard-2.2.0.jar \
                            IntelligentLearningScheme_glide-4.3.1:libs/glide-4.3.1.jar \
                            IntelligentLearningScheme_glide_annotations-4.3.1:libs/glide_annotations-4.3.1.jar \
                            IntelligentLearningScheme_glide_disklrucache-4.3.1:libs/glide_disklrucache-4.3.1.jar \
                            IntelligentLearningScheme_glide_gifdecoder-4.3.1:libs/glide_gifdecoder-4.3.1.jar \
                            IntelligentLearningScheme_gson-2.8.5:libs/gson-2.8.5.jar \
                            IntelligentLearningScheme_okgo-3.0.4:libs/okgo-3.0.4.jar \
                            IntelligentLearningScheme_okhttp-3.8.1:libs/okhttp-3.8.1.jar \
                            IntelligentLearningScheme_okio-1.13.0:libs/okio-1.13.0.jar \
                            constraint-layout-solver-1.1.3_:/../../library/third_jars/constraint-layout-solver-1.1.3.jar \
                            yxp_support-new-v4-annotations-25.3.1:/../../library/third_jars/support-annotations-25.3.1_.jar \
                            yxp_support-new-v4-compat-25.3.1:/../../library/third_jars/support-compat-25.3.1_.jar \
                            yxp_support-new-v4-core-ui-25.3.1:/../../library/third_jars/support-core-ui-25.3.1_.jar \
                            yxp_support-new-v4-fragment-25.3.1:/../../library/third_jars/support-fragment-25.3.1_.jar \
                            yxp_support-new-v4-media-compat-25.3.1:/../../library/third_jars/support-media-compat-25.3.1_.jar \
                            yxp_support-new-v4-core-utils-25.3.1:/../../library/third_jars/support-core-utils-25.3.1_.jar \
                            yxp_support-new-vector-drawable-25.3.1:/../../library/third_jars/support-vector-drawable-25.3.1_.jar \
                            yxp_support-new-animated-vector-drawable-25.3.1:/../../library/third_jars/support-animated-vector-drawable-25.3.1_.jar
  • 使用LOCAL_STATIC_JAVA_LIBRARIES 要引入的jar定义一个变量名。
  • 使用LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES 给定义的变量 设置一个引用路径。

再看引用aar

LOCAL_STATIC_JAVA_AAR_LIBRARIES := IntelligentLearningScheme_appcompat-v7-25.3.1 \
                                   IntelligentLearningScheme_recyclerview-v7-25.3.1 \
                                   IntelligentLearningScheme_constraint-layout-1.1.3 \
                                   IntelligentLearningScheme_utilcode-1.9.9

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := IntelligentLearningScheme_appcompat-v7-25.3.1:/../../library/aars/appcompat-v7-25.3.1.aar \
                            IntelligentLearningScheme_recyclerview-v7-25.3.1:/../../library/aars/recyclerview-v7-25.3.1.aar \
                            IntelligentLearningScheme_constraint-layout-1.1.3:/../../library/aars/constraint-layout-1.1.3.aar \
                            IntelligentLearningScheme_utilcode-1.9.9:libs/utilcode-1.9.9.aar

#需要引入library/aar的包名  
LOCAL_AAPT_FLAGS := --auto-add-overlay \
                    --extra-packages android.support.v7.appcompat \
                    --extra-packages android.support.constraint \
                    --extra-packages android.support.v7.recyclerview \
                    --extra-packages com.blankj.utilcode

可以发现不同的是:
  • 需要使用LOCAL_STATIC_JAVA_AAR_LIBRARIES 来给要引入的aar 定义一个变量(区别于LOCAL_STATIC_JAVA_LIBRARIES)。
  • 需要使用LOCAL_AAPT_FLAGS为aar添加一个包名。
需要注意的是:

android.support.constraint 的 targetSdkVersion='24'
appcompat、recyclerview、cardview 都是 minSdkVersion='9' , com.blankj.utilcode为 minSdkVersion='14'

所以在androidmianfest.xml加上
    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="24" />
注意:
  • 加上android:targetSdkVersion="24"会有一些问题,因为android6.0(23)加入了动态权限,targetSdkVersion="24"时需添加动态权限代码。
  • targetSdkVersion="24"改为targetSdkVersion="22"则不需要添加动态权限代码,但是会有编译错误,这里发现,只需要在编译一次此问题就会解决(比如加一个空格再上传代码编译,就会通过编译,以u27为例,暂不清楚为什么会这样,且只发现在constraint 库上有此问题,知道的同学望指教)
  • 编译的apk安装,有几率constraint 库会在setcontentview() 提示找不到此库。

完整android.mk文件

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_PROGUARD_ENABLED := disabled

LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_JAVA_LIBRARIES := dictenginelib \
                               org.apache.http.legacy \
                               constraint-layout-solver-1.1.3_ \
                               yxp_support-new-v4-annotations-25.3.1 \
                               yxp_support-new-v4-compat-25.3.1 \
                               yxp_support-new-v4-core-ui-25.3.1 \
                               yxp_support-new-v4-fragment-25.3.1 \
                               yxp_support-new-v4-media-compat-25.3.1 \
                               yxp_support-new-v4-core-utils-25.3.1 \
                               yxp_support-new-vector-drawable-25.3.1 \
                               yxp_support-new-animated-vector-drawable-25.3.1 \
                               IntelligentLearningScheme_cupboard-2.2.0 \
                               IntelligentLearningScheme_glide-4.3.1 \
                               IntelligentLearningScheme_glide_annotations-4.3.1 \
                               IntelligentLearningScheme_glide_disklrucache-4.3.1 \
                               IntelligentLearningScheme_glide_gifdecoder-4.3.1\
                               IntelligentLearningScheme_gson-2.8.5 \
                               IntelligentLearningScheme_okgo-3.0.4 \
                               IntelligentLearningScheme_okhttp-3.8.1 \
                               IntelligentLearningScheme_okio-1.13.0
                               
                               
LOCAL_STATIC_JAVA_AAR_LIBRARIES := IntelligentLearningScheme_appcompat-v7-25.3.1 \
                                   IntelligentLearningScheme_recyclerview-v7-25.3.1 \
                                   IntelligentLearningScheme_constraint-layout-1.1.3 \
                                   IntelligentLearningScheme_utilcode-1.9.9
    
        
        
#LOCAL_ASSET_DIR := $(LOCAL_PATH)/app/src/main/assets              
                               
LOCAL_JAVA_LIBRARIES := com.noahedu \
                        PenWriterLib \
                        com.writepen \
                        ucache

LOCAL_RESOURCE_DIR := \
      $(addprefix $(LOCAL_PATH)/../../library/yxp_src/dictenginelib/, res) \
      $(LOCAL_PATH)/res
#       $(addprefix $(LOCAL_PATH)/,$(extrafunction)/src/main/res) \             

LOCAL_SRC_FILES := $(call all-java-files-under, src) \
          src/com/noahedu/synclearning/engine/IBookService.aidl \
          src/com/noahedu/synclearning/engine/IBookServiceCallback.aidl
#           $(call all-java-files-under,$(extrafunction)/src/main/java)\


#需要引入library/aar的包名  
LOCAL_AAPT_FLAGS := --auto-add-overlay \
                    --extra-packages com.noahedu.DictEngine \
                    --extra-packages android.support.v7.appcompat \
                    --extra-packages android.support.constraint \
                    --extra-packages android.support.v7.recyclerview \
                    --extra-packages com.blankj.utilcode
    

LOCAL_PACKAGE_NAME := IntelligentLearningScheme

LOCAL_CERTIFICATE := testkey

include $(BUILD_PACKAGE)
include $(CLEAR_VARS)

#libs/recyclerview-v7-25.3.1.aar
#$(LOCAL_PATH)/../../library/jars/recyclerview-v7-25.3.1.aar

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := IntelligentLearningScheme_cupboard-2.2.0:libs/cupboard-2.2.0.jar \
                            IntelligentLearningScheme_glide-4.3.1:libs/glide-4.3.1.jar \
                            IntelligentLearningScheme_glide_annotations-4.3.1:libs/glide_annotations-4.3.1.jar \
                            IntelligentLearningScheme_glide_disklrucache-4.3.1:libs/glide_disklrucache-4.3.1.jar \
                            IntelligentLearningScheme_glide_gifdecoder-4.3.1:libs/glide_gifdecoder-4.3.1.jar \
                            IntelligentLearningScheme_gson-2.8.5:libs/gson-2.8.5.jar \
                            IntelligentLearningScheme_okgo-3.0.4:libs/okgo-3.0.4.jar \
                            IntelligentLearningScheme_okhttp-3.8.1:libs/okhttp-3.8.1.jar \
                            IntelligentLearningScheme_okio-1.13.0:libs/okio-1.13.0.jar \
                            constraint-layout-solver-1.1.3_:/../../library/third_jars/constraint-layout-solver-1.1.3.jar \
                            yxp_support-new-v4-annotations-25.3.1:/../../library/third_jars/support-annotations-25.3.1_.jar \
                            yxp_support-new-v4-compat-25.3.1:/../../library/third_jars/support-compat-25.3.1_.jar \
                            yxp_support-new-v4-core-ui-25.3.1:/../../library/third_jars/support-core-ui-25.3.1_.jar \
                            yxp_support-new-v4-fragment-25.3.1:/../../library/third_jars/support-fragment-25.3.1_.jar \
                            yxp_support-new-v4-media-compat-25.3.1:/../../library/third_jars/support-media-compat-25.3.1_.jar \
                            yxp_support-new-v4-core-utils-25.3.1:/../../library/third_jars/support-core-utils-25.3.1_.jar \
                            yxp_support-new-vector-drawable-25.3.1:/../../library/third_jars/support-vector-drawable-25.3.1_.jar \
                            yxp_support-new-animated-vector-drawable-25.3.1:/../../library/third_jars/support-animated-vector-drawable-25.3.1_.jar \
                            IntelligentLearningScheme_appcompat-v7-25.3.1:/../../library/aars/appcompat-v7-25.3.1.aar \
                            IntelligentLearningScheme_recyclerview-v7-25.3.1:/../../library/aars/recyclerview-v7-25.3.1.aar \
                            IntelligentLearningScheme_constraint-layout-1.1.3:/../../library/aars/constraint-layout-1.1.3.aar \
                            IntelligentLearningScheme_utilcode-1.9.9:libs/utilcode-1.9.9.aar


include $(BUILD_MULTI_PREBUILT)
#include $(BUILD_PREBUILT)

# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

如果代码或者资源不在默认路径,就需要额外指定,或者指定多个


# ‘:=’是赋值的意思;’+=’是追加的意思;‘\’表示连接符。 
LOCAL_MODULE_TAGS :=user eng tests optional 
- user: 指该模块只在user版本下才编译 
- eng: 指该模块只在eng版本下才编译 
- tests: 指该模块只在tests版本下才编译 
- optional:指该模块在所有版本下都编译


#指定asset目录
LOCAL_ASSET_DIR := $(LOCAL_PATH)/app/src/main/assets    

#指定res目录
LOCAL_RESOURCE_DIR := \
      $(addprefix $(LOCAL_PATH)/../../library/yxp_src/dictenginelib/, res) \
      $(LOCAL_PATH)/res 

#指定src/aidl目录
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
          src/com/noahedu/synclearning/engine/IBookService.aidl \
          src/com/noahedu/synclearning/engine/IBookServiceCallback.aidl \
          $(call all-Iaidl-files-under, src/com/noahedu/synclearning/engine/)

#指定arm目录
LOCAL_PREBUILT_JNI_LIBS_arm := libs/armeabi-v7a/libdecrypt.so \
                                    libs/armeabi-v7a/liblasa.so \
                                    libs/armeabi-v7a/libspeex.so \
                                    libs/armeabi-v7a/libddsdns.so

#指定arm64目录
LOCAL_PREBUILT_JNI_LIBS_arm64 :=libs/arm64-v8a/libdecrypt.so \
                                    libs/arm64-v8a/liblasa.so \
                                    libs/arm64-v8a/libspeex.so \
                                    libs/arm64-v8a/libddsdns.so
#指定androidmainfest.xml目录
LOCAL_MANIFEST_FILE := AndroidManifest.xml


发现总是编译不过的一个问题,看下面这段.mk片段


34行连接符 “ \ ”会把下面的35行的代码连成一片。 导致下面所有jar aar 都引用不到。因此编译就会报错

改正:

如果是注释:
连接符 “ \ ”后面要空一行。
连接符 “ \ ”后面要空一行。
连接符 “ \ ”后面要空一行。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容