Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e165ce1 authored by Colin Cross's avatar Colin Cross
Browse files

Copy resources from classes.jar when using AAPT2

When building with javac but without AAPT2 the final package is
created by copying classes.jar, deleting the class files, and
adding in the dex files.  This leaves any non-class java resources
in the final package.  When using AAPT2, the final package is
created from AAPT2's package-res.apk, so the java resources have
to be added back into the package manually.

Bug: 64272170
Test: m -j SystemUITests, check that the apk contains mockito-extensions/*
Change-Id: I6649f7f2fbf63ff5001f4731e22960f857726c70
parent 5bebd3fb
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -2692,6 +2692,17 @@ define add-carried-jack-resources
fi
endef

# Add resources (non .class files) from a jar to a package
# $(1): the package file
# $(2): the jar file
# $(3): temporary directory
define add-jar-resources-to-package
  rm -rf $(3)
  mkdir -p $(3)
  unzip -qo $(2) -d $(3) $$(zipinfo -1 $(2) | grep -v -E "\.class$$")
  $(JAR) uf $(1) -C $(3) .
endef

# Sign a package using the specified key/cert.
#
define sign-package
+6 −0
Original line number Diff line number Diff line
@@ -563,7 +563,10 @@ else
    $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
endif
endif

$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources
$(LOCAL_BUILT_MODULE): PRIVATE_FULL_CLASSES_JAR := $(full_classes_jar)
$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
ifdef LOCAL_USE_AAPT2
$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
@@ -592,6 +595,9 @@ ifeq ($(full_classes_jar),)
	$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
else  # full_classes_jar
	$(add-dex-to-package)
ifdef LOCAL_USE_AAPT2
	$(call add-jar-resources-to-package,$@,$(PRIVATE_FULL_CLASSES_JAR),$(PRIVATE_RESOURCE_INTERMEDIATES_DIR))
endif
endif  # full_classes_jar
ifdef LOCAL_JACK_ENABLED
	$(add-carried-jack-resources)