Add support for prebuilt AARs.

- You can give a .aar as source file to a prebuilt static Java library
  module. The build system will set up dependencies and rules to extract
  classes.jar and other resource files.
- To build against a prebuilt AAR module, use:
  LOCAL_STATIC_JAVA_AAR_LIBRARIES := <module names of aar prebuilt AARs>
  The build system will set up rules to merge the library's
  AndroidManifest.xml with the main AndroidManifest.xml, add the AAR's
  resource dirs and link/merge the AAR's classes.jar.

Bug: 18168693
Change-Id: Ic2c1d20572a93bd98dbc72f8a39e26b459e442c2
This commit is contained in:
Ying Wang 2014-10-29 15:48:32 -07:00
parent e4cbc2af5f
commit e9dd9f2bfc
5 changed files with 43 additions and 9 deletions

View file

@ -11,13 +11,27 @@ else
full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
endif
my_full_libs_manifest_files := $(LOCAL_FULL_LIBS_MANIFEST_FILES)
my_full_libs_manifest_deps := $(LOCAL_FULL_LIBS_MANIFEST_FILES)
# Set up dependency on 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
# Set up rules to merge library manifest files
ifdef LOCAL_FULL_LIBS_MANIFEST_FILES
ifdef my_full_libs_manifest_files
main_android_manifest := $(full_android_manifest)
full_android_manifest := $(intermediates.COMMON)/AndroidManifest.xml
$(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(LOCAL_FULL_LIBS_MANIFEST_FILES)
$(full_android_manifest) : $(main_android_manifest) $(LOCAL_FULL_LIBS_MANIFEST_FILES)
@echo "Merge android manifest files: $@ <-- $^"
$(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files)
$(full_android_manifest) : $(main_android_manifest) $(my_full_libs_manifest_deps)
@echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)"
@mkdir -p $(dir $@)
$(hide) $(ANDROID_MANIFEST_MERGER) --main $< --libs $(PRIVATE_LIBS_MANIFESTS) \
--out $@

View file

@ -30,6 +30,7 @@ LOCAL_MODULE_TAGS:=
LOCAL_SRC_FILES:=
LOCAL_PREBUILT_OBJ_FILES:=
LOCAL_STATIC_JAVA_LIBRARIES:=
LOCAL_STATIC_JAVA_AAR_LIBRARIES:=
LOCAL_STATIC_LIBRARIES:=
# Group static libraries with "-Wl,--start-group" and "-Wl,--end-group" when linking.
LOCAL_GROUP_STATIC_LIBRARIES:=

View file

@ -52,6 +52,9 @@ else
endif
endif
# LOCAL_STATIC_JAVA_AAR_LIBRARIES are special LOCAL_STATIC_JAVA_LIBRARIES
LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))

View file

@ -192,6 +192,8 @@ endif # LOCAL_EMMA_INSTRUMENT
rs_compatibility_jni_libs :=
include $(BUILD_SYSTEM)/android_manifest.mk
#################################
include $(BUILD_SYSTEM)/java.mk
#################################
@ -201,8 +203,6 @@ ifeq ($(LOCAL_SDK_RES_VERSION),)
LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
endif
include $(BUILD_SYSTEM)/android_manifest.mk
$(LOCAL_INTERMEDIATE_TARGETS): \
PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))

View file

@ -247,10 +247,26 @@ ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
# while the deps should be in the common dir, so we make a copy in the common dir.
# For nonstatic library, $(common_javalib_jar) is the dependency file,
# while $(common_classes_jar) is used to link.
common_classes_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/classes.jar
common_javalib_jar := $(dir $(common_classes_jar))javalib.jar
common_classes_jar := $(intermediates.COMMON)/classes.jar
common_javalib_jar := $(intermediates.COMMON)/javalib.jar
$(common_classes_jar) : $(my_prebuilt_src_file) | $(ACP)
$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
ifneq ($(filter %.aar, $(my_prebuilt_src_file)),)
# This is .aar file, archive of classes.jar and Android resources.
my_src_jar := $(intermediates.COMMON)/aar/classes.jar
$(my_src_jar) : $(my_prebuilt_src_file)
$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
$(hide) unzip -qo -d $(dir $@) $<
# Make sure the extracted classes.jar has a new timestamp.
$(hide) touch $@
else
# This is jar file.
my_src_jar := $(my_prebuilt_src_file)
endif
$(common_classes_jar) : $(my_src_jar) | $(ACP)
$(transform-prebuilt-to-target)
$(common_javalib_jar) : $(common_classes_jar) | $(ACP)