From: Ying Wang Date: Tue, 5 May 2015 02:21:48 +0000 (-0700) Subject: Raise SDK version for ProGuard processing when app links support library. X-Git-Tag: android-x86-6.0-r1~253 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4f5d0e60b441f009f78ef6595172ffa11dd69a2d;p=android-x86%2Fbuild.git Raise SDK version for ProGuard processing when app links support library. When an app's LOCAL_SDK_VERSION is lower than the support library's LOCAL_SDK_VERSION, we artifically raises the "SDK version" "linked" by ProGuard, to - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version. - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version. This allows us to remove the dangerous ProGuard flag "-dontwarn android.support.**". Notes: - We don't raise the app's LOCAL_SDK_VERSION, so that the app's own code is still unable to use the higher SDK version. - For platform build, we can't just raise to the "current" SDK, because would break apps that use APIs removed from the current SDK. We raise it to framework.jar instead, which contains the most complete symbol set. Bug: 20658265 Change-Id: I90099073457a65cb8031fbaec6b396d68ce614a7 (cherry picked from commit 8e8d1e7abadb53d5dcb211fac6ab6ed20f5dc9ac) --- diff --git a/core/java.mk b/core/java.mk index 02745a80c..73b8780ea 100644 --- a/core/java.mk +++ b/core/java.mk @@ -432,8 +432,29 @@ ifneq ($(filter-out full custom nosystem obfuscation optimization shrinktests,$( $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED)) endif proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary + +# Hack: see b/20667396 +# When an app's LOCAL_SDK_VERSION is lower than the support library's LOCAL_SDK_VERSION, +# we artifically raises the "SDK version" "linked" by ProGuard, to +# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version. +# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version. +my_support_library_sdk_raise := +ifneq (,$(filter android-support-%,$(LOCAL_STATIC_JAVA_LIBRARIES))) +ifdef LOCAL_SDK_VERSION +ifeq (,$(filter current system_current, $(LOCAL_SDK_VERSION))) +ifdef TARGET_BUILD_APPS + my_support_library_sdk_raise := $(call java-lib-files, sdk_vcurrent) +else + # For platform build, we can't just raise to the "current" SDK, + # that would break apps that use APIs removed from the current SDK. + my_support_library_sdk_raise := $(call java-lib-files,framework) +endif +endif +endif +endif + # jack already has the libraries in its classpath and doesn't support jars -legacy_proguard_flags := $(addprefix -libraryjars ,$(full_shared_java_libs)) +legacy_proguard_flags := $(addprefix -libraryjars ,$(my_support_library_sdk_raise) $(full_shared_java_libs)) common_proguard_flags := \ -forceprocessing \ -printmapping $(proguard_dictionary) @@ -501,7 +522,7 @@ extra_input_jar := endif $(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) $(proguard_flag_files) | $(ACP) $(PROGUARD) +$(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(proguard_flag_files) | $(ACP) $(PROGUARD) $(call transform-jar-to-proguard) else # LOCAL_PROGUARD_ENABLED not defined diff --git a/core/proguard_basic_keeps.flags b/core/proguard_basic_keeps.flags index 4a85db0f8..6b3715a73 100644 --- a/core/proguard_basic_keeps.flags +++ b/core/proguard_basic_keeps.flags @@ -58,7 +58,12 @@ # Don't warn about those in case this app is linking against an older # platform version. We know about them, and they are safe. # See proguard-android.txt in the SDK package. --dontwarn android.support.** +# +# DO NOT USE THIS: We figured it's dangerous to blindly ignore all support library warnings. +# ProGuard may strip members of subclass of unknown super classes, in case an app is linking against +# LOCAL_SDK_VERSION lower than the support library's LOCAL_SDK_VERSION. +# See bug/20658265. +# -dontwarn android.support.** # Less spammy. -dontnote