问题
Application (developed in Android Studio) uses AAR
as a library. I need to build this app in AOSP
tree. So I created 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)
Build completes successfully but the issue is that AAR
contains number of JAR files in its 'libs' directory. And it seems that these JARs are not included into build so application crashes with NoClassDefFoundError
.
Is AOSP missing full support of the AAR
? Or do I miss something? Thanks. I use Android 6.0.1.
回答1:
The way you are doing is correct. And jar files included in aar will also be included by this. I think you have missed to include aapt flags in that.
LOCAL_AAPT_FLAGS += --extra-packages your.package.name
回答2:
I ended up with the following:
-in application's Android.mk:
LOCAL_STATIC_JAVA_AAR_LIBRARIES += coollibrary
include $(LOCAL_PATH)/java-static-lib-from-aar.mk
-java-static-lib-from-aar.mk:
define list-jar-libs-from-aar
$(foreach f, $(2), $(shell if [ -f $(LOCAL_PATH)/$(f)/$(1).aar ]; then unzip -Z1 $(LOCAL_PATH)/$(f)/$(1).aar libs/*.jar | sed 's/libs\///g; s/\.jar//g'; fi))
endef
define build-jar-lib-from-aar
$(2): $(1)
-mkdir -p $(dir $2);\
cp -fp $1 $2
endef
MY_STATIC_JAVA_LIBS := $(foreach aar,$(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
$(foreach jar, $(call list-jar-libs-from-aar,$(aar), libs aosplibs),\
$(aar)_$(jar)))
$(info Adding following java libraries from AAR(s) into LOCAL_STATIC_JAVA_LIBRARIES: $(MY_STATIC_JAVA_LIBS))
LOCAL_STATIC_JAVA_LIBRARIES += $(MY_STATIC_JAVA_LIBS)
$(foreach aar,$(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
$(foreach jar, $(call list-jar-libs-from-aar,$(aar), libs aosplibs),\
$(eval $(call build-jar-lib-from-aar,$(call intermediates-dir-for,JAVA_LIBRARIES,$(aar),,COMMON)/aar/libs/$(jar).jar,$(call intermediates-dir-for,JAVA_LIBRARIES,$(aar)_$(jar),,COMMON)/javalib.jar))))
java-static-lib-from-aar.mk assumes that AARs reside in ./libs and aosplibs directories.
回答3:
Raising the dead here, I've experienced the same beahviour. Same goes to *.so files under ./jni/. and aar assets. Looking into $(BUILD_MULTI_PREBUILT), I see it looks only for classes jar and res files.
I ended up extracting al those components (*.so, *.jar, assets), and added them explicitly in my app's Android.mk.
来源:https://stackoverflow.com/questions/42968311/aar-support-in-android-mk-dependencies-are-not-picked-up-by-aosp-build