Commit aa1fce78 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Make R8 not require ",allowaccessmodification"

via a custom patch to it that causes it to consider all
-keep rules to have implicit ",allowaccessmodification".

Causes many more downstream play services methods to be
removed.

Change-Id: I9532fe9621d9a011202a1b9044cb3467ae207a18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223651
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773790}
parent aa6c0a6c
...@@ -1323,7 +1323,7 @@ deps = { ...@@ -1323,7 +1323,7 @@ deps = {
'packages': [ 'packages': [
{ {
'package': 'chromium/third_party/r8', 'package': 'chromium/third_party/r8',
'version': 'bri3RbTe5EACoEqrT7RBNXf6QZ1fIHWpsWpg9lW-JEQC', 'version': 'gobCh01BNwJNyLHHNFUmLWSMaAbe4x3izuzBFzxQpDoC',
}, },
], ],
'condition': 'checkout_android', 'condition': 'checkout_android',
......
...@@ -77,6 +77,6 @@ ...@@ -77,6 +77,6 @@
} }
# Protobuf java lite runtime uses reflection # Protobuf java lite runtime uses reflection
-keepclassmembers,allowaccessmodification class * extends com.google.protobuf.GeneratedMessageLite { -keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
<fields>; <fields>;
} }
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
-keep @org.chromium.base.annotations.UsedByReflection class ** {} -keep @org.chromium.base.annotations.UsedByReflection class ** {}
# Keeps for method level annotations. # Keeps for method level annotations.
-keepclasseswithmembers,allowaccessmodification class ** { -keepclasseswithmembers class ** {
@org.chromium.base.annotations.AccessedByNative <fields>; @org.chromium.base.annotations.AccessedByNative <fields>;
} }
-keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { -keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNative <methods>; @org.chromium.base.annotations.CalledByNative <methods>;
} }
-keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { -keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNativeUnchecked <methods>; @org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
} }
-keepclasseswithmembers class ** { -keepclasseswithmembers class ** {
......
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
} }
# Protobuf java lite runtime uses reflection # Protobuf java lite runtime uses reflection
-keepclassmembers,allowaccessmodification class * extends com.google.protobuf.GeneratedMessageLite { -keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
<fields>; <fields>;
} }
...@@ -198,13 +198,13 @@ ...@@ -198,13 +198,13 @@
-keep @org.chromium.base.annotations.UsedByReflection class ** {} -keep @org.chromium.base.annotations.UsedByReflection class ** {}
# Keeps for method level annotations. # Keeps for method level annotations.
-keepclasseswithmembers,allowaccessmodification class ** { -keepclasseswithmembers class ** {
@org.chromium.base.annotations.AccessedByNative <fields>; @org.chromium.base.annotations.AccessedByNative <fields>;
} }
-keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { -keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNative <methods>; @org.chromium.base.annotations.CalledByNative <methods>;
} }
-keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { -keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNativeUnchecked <methods>; @org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
} }
-keepclasseswithmembers class ** { -keepclasseswithmembers class ** {
......
...@@ -482,7 +482,6 @@ action("cronet_combine_proguard_flags") { ...@@ -482,7 +482,6 @@ action("cronet_combine_proguard_flags") {
# Massage the proguard rules to work with AppReduce. # Massage the proguard rules to work with AppReduce.
"//components/cronet/android/cronet_appreduce_workaround.patch", "//components/cronet/android/cronet_appreduce_workaround.patch",
"//components/cronet/android/cronet_appreduce_workaround2.patch",
"//components/cronet/android/cronet_impl_native_proguard.cfg", "//components/cronet/android/cronet_impl_native_proguard.cfg",
] ]
outputs = [ "$target_gen_dir/cronet_impl_native_proguard.cfg" ] outputs = [ "$target_gen_dir/cronet_impl_native_proguard.cfg" ]
......
This patch works as a supplement for cronet_appreduce_workaround.patch.
See crbug.com/1087646 on why this is needed.
For more information, also see cronet_appreduce_workaround.patch.
--- base/android/proguard/chromium_code.flags 2020-05-29 11:34:48.748109273 -0700
+++ modified.flags 2020-05-29 12:20:30.692111915 -0700
@@ -34,13 +34,13 @@
-keep @org.chromium.base.annotations.UsedByReflection class ** {}
# Keeps for method level annotations.
--keepclasseswithmembers,allowaccessmodification class ** {
+-keepclasseswithmembers class ** {
@org.chromium.base.annotations.AccessedByNative <fields>;
}
--keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
+-keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNative <methods>;
}
--keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
+-keepclasseswithmembers,includedescriptorclasses class ** {
@org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
}
-keepclasseswithmembers class ** {
...@@ -18,7 +18,6 @@ desugar_jdk_libs.json ...@@ -18,7 +18,6 @@ desugar_jdk_libs.json
R8 is a proguard-like optimizer that also has the ability to dex. R8 is a proguard-like optimizer that also has the ability to dex.
Local Modifications: Local Modifications:
* Cherry-picked R8 commit: b8464335ec1e587bde88d7a12c90d59531be10de
* Refer to commit descriptions within "patches" directory. * Refer to commit descriptions within "patches" directory.
* Added "playground" directory for quick "how does this optimize" tests. * Added "playground" directory for quick "how does this optimize" tests.
...@@ -27,7 +26,7 @@ Update Instructions: ...@@ -27,7 +26,7 @@ Update Instructions:
git clone https://r8.googlesource.com/r8 git clone https://r8.googlesource.com/r8
cd r8 cd r8
# Apply patches: # Apply patches:
git am $CHROMIUM_SRC/third_party/r8/patches *.patch git am $CHROMIUM_SRC/third_party/r8/patches/*.patch
# Build: # Build:
tools/gradle.py r8 tools/gradle.py r8
# Shrink (improves r8/d8 launch time): # Shrink (improves r8/d8 launch time):
......
From 69f75c5fa4d5dd8607ec54df94b9c48d68dd5422 Mon Sep 17 00:00:00 2001
From: Andrew Grieve <agrieve@chromium.org>
Date: Sun, 31 May 2020 22:09:27 -0400
Subject: [PATCH] Allow access modification everywhere
Chrome does not need need -keep to maintain original visibility.
Loosening this constraint allows for better optimization, and is easier
than adding ",allowaccessmodification" to every single -keep rule.
---
.../java/com/android/tools/r8/shaking/AppInfoWithLiveness.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
index 275b882fc..be214ad60 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -927,7 +927,7 @@ public class AppInfoWithLiveness extends AppInfoWithClassHierarchy
public boolean isAccessModificationAllowed(DexReference reference) {
assert options().getProguardConfiguration().isAccessModificationAllowed();
- return allowAccessModification.contains(reference) || !isPinned(reference);
+ return true;
}
public boolean isPinned(DexReference reference) {
--
2.27.0.rc0.183.gde8f92d652-goog
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment