How to include .aar in AOSP with android.mk

后端 未结 1 720
感动是毒
感动是毒 2021-01-06 11:34

I need to build an application with android.mk in aosp build tree. I have a custom .arr lib with me, Which resides in the following folder apps/libs/mylib.aar

Anyone

相关标签:
1条回答
  • 2021-01-06 12:22

    I know I am too late, but still worth sharing this information. LOCAL_STATIC_JAVA_AAR_LIBRARIES support of AAPT2 was broken at some point. So even if you add your library as descibed above, resources from aar would not be linked.

    from AOSP git history:

    Oct 30, 2014 Add support for prebuilt AARs. Aars were unpacked into out/.../intermediates* dirs and linked to the aosp modules.

    Dec 5, 2015 Support to build with AAPT2 As you can see in core/android_manifest.mk:26, linking unpacked aars was not necessary anymore, because AAPT2 supports linking directly into arrays.

    But unfortunately they were not added as --extra-packages correctly.

    The bug was fixed in android-p-preview-5.

    If you are still developing for android 8 or 8.1 please add these changes manually or cherry-pick them in your tree. Worked perfectly for me.

    UPD 2018-11-28

    Exact steps to fix it for android 8.1 and earlier:

    1) cherry-pick fix Dec 5, 2015 Support to build with AAPT2 from aosp

    2) in build/core/prebuilt_internal.mk:593 add parameter --auto-add-overlay

    $(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages --auto-add-overlay
    

    3) As RenderScript was refactored much later, you have to define your aar module explicitly:

    include $(CLEAR_VARS)
    LOCAL_MODULE := my-library-module
    LOCAL_MODULE_TAGS := optional
    LOCAL_SRC_FILES := my-library-module.aar
    # Provide resources directory in order to compile them, enable AAPT2 for this module
    LOCAL_RESOURCE_DIR := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/aar/res)
    LOCAL_USE_AAPT2 := true
    # if LOCAL_RENDERSCRIPT_TARGET_API >= 21, resources won't get compiled. Shouldn't affect anything else
    LOCAL_RENDERSCRIPT_TARGET_API := 20
    LOCAL_MODULE_CLASS := JAVA_LIBRARIES
    LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
    LOCAL_BUILT_MODULE_STEM := javalib.jar
    LOCAL_UNINSTALLABLE_MODULE := true
    include $(BUILD_PREBUILT)
    

    Disclaimer: this is rather a hacky workaround that worked for me. Due to lack of time and urgent need to support older client versions, I may have missed some use cases.

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