android 4.4/5.1上使用aar的問題

夢書發表於2016-12-22

在Android6.0上可以使用LOCAL_STATIC_JAVA_AAR_LIBRARIES。build指令碼會把指定的aar解壓縮到臨時目錄,並將class.jar和res新增到對應的變數。

LOCAL_STATIC_JAVA_AAR_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
    ifdef LOCAL_STATIC_JAVA_AAR_LIBRARIES
    my_full_libs_manifest_deps += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
      $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/classes.jar)
    my_full_libs_manifest_files += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
      $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/AndroidManifest.xml)

    LOCAL_RESOURCE_DIR += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
      $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/res)
    endif

LOCAL_STATIC_JAVA_AAR_LIBRARIES在Android4.4不存在,但是隻要參照上面的步驟就可以了。手動將aar解壓縮後新增到你的工程,並使用下面類似的語句:

LOCAL_STATIC_JAVA_LIBRARIES += lib_android_recyclerview

    LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.recyclerview
    LOCAL_RESOURCE_DIR += $(addprefix $(LOCAL_PATH)/, android-recyclerview-v7/res)

    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += lib_android_recyclerview:android-recyclerview-v7/classes.jar

 

相關文章