aar support in Android.mk

后端 未结 3 2006
终归单人心
终归单人心 2020-12-08 12:03

I am doing android custom ROM development now. the build system of aosp is based on Android.mk, But I want to include some aar libraries, is it possible to include aar libar

相关标签:
3条回答
  • 2020-12-08 12:38

    My Android.mk

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    
    LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
    LOCAL_STATIC_JAVA_LIBRARIES += android-common
    
    LOCAL_SRC_FILES := $(call all-java-files-under, app/src)
    
    LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res
    LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
    
    LOCAL_MANIFEST_FILE :=  app/src/main/AndroidManifest.xml
    
    LOCAL_PACKAGE_NAME := PackageName
    
    LOCAL_SDK_VERSION := current
    
    LOCAL_PROGUARD_FLAG_FILES := app/proguard-rules.pro
    
    LOCAL_AAPT_FLAGS := --auto-add-overlay
    LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat
    LOCAL_AAPT_FLAGS += --extra-packages com.exp.librairy
    
    LOCAL_STATIC_JAVA_AAR_LIBRARIES := explibrairy
    
    include $(BUILD_PACKAGE)
    
    #Build aar libs
    include $(CLEAR_VARS)
    LOCAL_PREBUILT_STATIC_AAR_LIBRARIES := explibrairy:project/build/outputs/aar/explibrairy-debug.aar
    include $(BUILD_MULTI_PREBUILT)
    
    include $(call all-makefiles-under, $(LOCAL_PATH))
    
    0 讨论(0)
  • 2020-12-08 12:45

    Kostiantyn Luzan's answer has a problem. After compile, the resources in the aar will be added to my main package's R file, but not in the aar package's R file. For example, the aar's package name is my.aar, the main project's package name is my.main. The aar has a string named "string_in_aar". After compile, the strings id is my.main.R.string_in_aar rather than my.aar.R.string_in_aar. This makes the apk crash, because the code in the aar uses my.aar.R.string_in_aar.

    The solution is use: LOCAL_AAPT_FLAGS += --extra-packages {aar package name}. You will get two R file. They has the some content. One's package is the main package, the other is the aar package.

    0 讨论(0)
  • 2020-12-08 13:03

    You should add following blocks into your Android.mk

    LOCAL_STATIC_JAVA_AAR_LIBRARIES:= <aar alias>
    .
    .
    .
    include $(BUILD_PACKAGE)
    
    include $(CLEAR_VARS)
    
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := <aar alias>:libs/<lib file>.aar
    
    include $(BUILD_MULTI_PREBUILT)
    

    Please also be aware of satisfy minSdkVersion required by library into your manifest file.

    0 讨论(0)
提交回复
热议问题