美文网首页Android AAR
android.mk引用aar

android.mk引用aar

作者: duoduo7628 | 来源:发表于2019-02-26 11:19 被阅读0次

    先看看引入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_LIBRARIESLOCAL_STATIC_JAVA_AAR_LIBRARIES

    完整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目录
    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
    
    
    

    相关文章

      网友评论

        本文标题:android.mk引用aar

        本文链接:https://www.haomeiwen.com/subject/xeaoyqtx.html