From f22aca1e47a4cb7833afb42a90eee363a2258cb5 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 21 Feb 2017 13:11:13 +0000 Subject: [PATCH] Filter JUnit and android.test classes from applications using proguard The new javac/desugar/proguard/dx based toolchain can fail if there are duplicate classes in the -injars and -libraryjars passed to proguard. That causes problems for b/30188076 which is attempting to remove various junit and android.test classes from the API because it requires the changes to add those classes statically to applications are submitted simultaneously with the change to remove the classes from the API which is not feasible. This change simply causes Proguard to ignore the classes from the application JAR so it will always use them from the library. That allows the changes to be done separately and only requires that this change is reverted simultaneously with the change to update the API. Bug: 30188076 Test: make checkbuild and make -j ANDROID_FORCE_JACK_ENABLED=disabled checkbuild Change-Id: I6ed6c45a159d6261d90245551aa2913cc82d2e8b --- core/definitions.mk | 3 ++- core/java.mk | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/definitions.mk b/core/definitions.mk index e9ec26a23d..137bddff58 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2889,7 +2889,8 @@ endef ########################################################### define transform-jar-to-proguard @echo Proguard: $@ -$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \ +$(hide) $(PROGUARD) -injars '$<$(PRIVATE_PROGUARD_INJAR_FILTERS)' \ + -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \ $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR)) endef diff --git a/core/java.mk b/core/java.mk index d1ac6c7cce..bc7b1c14e9 100644 --- a/core/java.mk +++ b/core/java.mk @@ -619,6 +619,23 @@ extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROG else extra_input_jar := endif + +# If not using jack and building against the current SDK version then filter +# out junit and android.test classes from the application that are to be +# removed from the Android API as part of b/30188076 but which are still +# present in the Android API. This is to allow changes to be made to the +# build to statically include those classes into the application without +# simultaneously removing those classes from the API. +proguard_injar_filters := +ifndef LOCAL_JACK_ENABLED +ifdef LOCAL_SDK_VERSION +ifeq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION))) +proguard_injar_filters := (!junit/framework/**,!junit/runner/**,!android/test/**) +endif +endif +endif + +$(full_classes_proguard_jar): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters) $(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar) $(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS) $(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) | $(PROGUARD)