From 1d64623105b4f7bae84b699034994d576d6d93dc Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 17 Nov 2017 13:11:26 -0800 Subject: [PATCH 1/2] Export proguard flags from static android libraries and aar prebuilts Test: m Contacts, classes-proguard.jar has same contents Test: rm -rf out; tapas Contacts; m Change-Id: Id7a92fb2c44913bccbfcbeae127355b4de588e4d Merged-In: Id7a92fb2c44913bccbfcbeae127355b4de588e4d (cherry picked from commit 1417c177ac9b942c4f1ae602f420444c72a90d6a) --- core/clear_vars.mk | 1 + core/java.mk | 6 ++++++ core/prebuilt_internal.mk | 8 ++++++++ core/static_java_library.mk | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 09f9be5ee..06518ee41 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -78,6 +78,7 @@ LOCAL_EXPORT_C_INCLUDE_DEPS:= LOCAL_EXPORT_C_INCLUDE_DIRS:= LOCAL_EXPORT_HEADER_LIBRARY_HEADERS:= LOCAL_EXPORT_PACKAGE_RESOURCES:= +LOCAL_EXPORT_PROGUARD_FLAG_FILES:= LOCAL_EXPORT_SHARED_LIBRARY_HEADERS:= LOCAL_EXPORT_STATIC_LIBRARY_HEADERS:= LOCAL_EXTRACT_APK:= diff --git a/core/java.mk b/core/java.mk index 3e0123b34..cfe253973 100644 --- a/core/java.mk +++ b/core/java.mk @@ -644,6 +644,12 @@ ifeq ($(filter shrinktests,$(LOCAL_PROGUARD_ENABLED)),) common_proguard_flags += -dontshrink # don't shrink tests by default endif # shrinktests endif # test package +ifneq ($(LOCAL_PROGUARD_ENABLED),custom) + ifdef LOCAL_USE_AAPT2 + common_proguard_flag_files += $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES),\ + $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags) + endif +endif ifneq ($(common_proguard_flag_files),) common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files)) # This is included from $(BUILD_SYSTEM)/proguard.flags diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index 69df2d133..2a9ad1f0e 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -566,12 +566,16 @@ my_src_aar := $(filter %.aar, $(my_prebuilt_src_file)) ifneq ($(my_src_aar),) # This is .aar file, archive of classes.jar and Android resources. my_src_jar := $(intermediates.COMMON)/aar/classes.jar +my_src_proguard_options := $(intermediates.COMMON)/aar/proguard.txt +$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS := $(my_src_proguard_options) $(my_src_jar) : $(my_src_aar) $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) $(dir $@)/res $(hide) unzip -qo -d $(dir $@) $< # Make sure the extracted classes.jar has a new timestamp. $(hide) touch $@ + # Make sure the proguard file exists and has a new timestamp. + $(hide) touch $(dir $@)/proguard.txt endif @@ -595,6 +599,10 @@ endif ifdef LOCAL_USE_AAPT2 ifneq ($(my_src_aar),) + +$(intermediates.COMMON)/export_proguard_flags : $(my_src_proguard_options) + $(transform-prebuilt-to-target) + LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) ifeq ($(LOCAL_SDK_RES_VERSION),) LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) diff --git a/core/static_java_library.mk b/core/static_java_library.mk index 6645af555..834834975 100644 --- a/core/static_java_library.mk +++ b/core/static_java_library.mk @@ -118,6 +118,13 @@ framework_res_package_export_deps := \ endif endif +ifdef LOCAL_USE_AAPT2 +$(intermediates.COMMON)/export_proguard_flags: $(addprefix $(LOCAL_PATH)/,$(LOCAL_EXPORT_PROGUARD_FLAG_FILES)) + @echo "Export proguard flags: $@" + rm -f $@ + cat $+ >$@ +endif + # add --non-constant-id to prevent inlining constants. # AAR needs text symbol file R.txt. ifdef LOCAL_USE_AAPT2 From e4936e1c2dff7e490049edbabb319f08a78ce16a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 27 Dec 2017 17:58:21 -0800 Subject: [PATCH 2/2] Remove obsolete proguard options LOCAL_PROGUARD_ENABLED := shrinktests is never set. proguard_tests.flags is entirely comments. proguard.emma.flags only references emma classes, but we use jacoco now. Test: m checkbuild Change-Id: I84a59a8c1b66f75d7ccbaa7da8e937430b4490c8 --- core/java.mk | 9 +-------- core/proguard.emma.flags | 4 ---- core/proguard_tests.flags | 26 -------------------------- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 core/proguard.emma.flags delete mode 100644 core/proguard_tests.flags diff --git a/core/java.mk b/core/java.mk index cfe253973..6e9fea041 100644 --- a/core/java.mk +++ b/core/java.mk @@ -593,7 +593,7 @@ $(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COM # Run proguard if necessary ifdef LOCAL_PROGUARD_ENABLED -ifneq ($(filter-out full custom nosystem obfuscation optimization shrinktests,$(LOCAL_PROGUARD_ENABLED)),) +ifneq ($(filter-out full custom nosystem obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),) $(warning while processing: $(LOCAL_MODULE)) $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED)) endif @@ -634,15 +634,8 @@ common_proguard_flags := -forceprocessing common_proguard_flag_files := ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),) common_proguard_flag_files += $(BUILD_SYSTEM)/proguard.flags -ifeq ($(LOCAL_EMMA_INSTRUMENT),true) -common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags -endif -# If this is a test package, add proguard keep flags for tests. ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),) -common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_tests.flags -ifeq ($(filter shrinktests,$(LOCAL_PROGUARD_ENABLED)),) common_proguard_flags += -dontshrink # don't shrink tests by default -endif # shrinktests endif # test package ifneq ($(LOCAL_PROGUARD_ENABLED),custom) ifdef LOCAL_USE_AAPT2 diff --git a/core/proguard.emma.flags b/core/proguard.emma.flags deleted file mode 100644 index bf9408621..000000000 --- a/core/proguard.emma.flags +++ /dev/null @@ -1,4 +0,0 @@ -# Keep everything for the emma classes --keep class com.vladium.** { - *; -} diff --git a/core/proguard_tests.flags b/core/proguard_tests.flags deleted file mode 100644 index 1f840bc21..000000000 --- a/core/proguard_tests.flags +++ /dev/null @@ -1,26 +0,0 @@ -# Keep everything for tests -# This flag has been moved to the makefiles and is set for tests by default. -#-dontshrink - -# But we may want to obfuscate if the main app gets obfuscated. -# This flag has been moved to the makefiles. -#-dontobfuscate - -#-keep class * extends junit.framework.TestCase { -# public void test*(); -#} - -#-keepclasseswithmembers class * { -# public static void run(); -# public static junit.framework.Test suite(); -#} - -# some AllTests don't include run(). -#-keepclasseswithmembers class * { -# public static junit.framework.Test suite(); -#} - -#-keep class * extends junit.framework.TestSuite -#-keep class * extends android.app.Instrumentation -#-keep class * extends android.test.TestSuiteProvider -