From 6eff9fcd9bce74c436c3ce33355f1b7acbcc3b34 Mon Sep 17 00:00:00 2001 From: smaier Date: Thu, 14 Jul 2016 07:36:22 -0700 Subject: [PATCH] Fixing WebView ProGuard config for annotations WebView used to not -keep its annotations. Thus, when trying to do anything useful with ProGuard, it appeared that the annotations were not being obeyed, since ProGuard had already stripped them out. Note - since we still have the -keepnames class *** { *; }, this effectively prevents any real optimizations from being run. This change brings the .dex size down 7356 B, and removes 12 types, 5 fields, and 57 strings. However, these all seem inconsequential, as this is the method/class diff of this change: org.chromium.base.Log - void d(java.lang.String,java.lang.String,java.lang.Object) - void v(java.lang.String,java.lang.String) - void d(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object,java.lang.Object) - java.lang.String formatLogWithStack(java.lang.String,java.lang.Object[]) - void d(java.lang.String,java.lang.String) - void v(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object,java.lang.Object) - void () - void d(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object) - java.lang.String getCallOrigin() - void debug(java.lang.String,java.lang.String,java.lang.Object[]) - void verbose(java.lang.String,java.lang.String,java.lang.Object[]) BUG=541543,583143,624827,627139 Review-Url: https://codereview.chromium.org/2147743002 Cr-Commit-Position: refs/heads/master@{#405491} --- android_webview/apk/java/proguard.flags | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/android_webview/apk/java/proguard.flags b/android_webview/apk/java/proguard.flags index 3b3f2c6332c785..3589ce9223dbc7 100644 --- a/android_webview/apk/java/proguard.flags +++ b/android_webview/apk/java/proguard.flags @@ -8,10 +8,14 @@ # Keep all runtime visible annotations. -keepattributes RuntimeVisibleAnnotations - -# Disable optimization as this causes proguard to remove seemingly random stuff, -# including things explicitly kept in this configuration. --dontoptimize +# Keeping annotations - if we remove these keeps, ProGuard will eliminate the +# annotations themselves, which will prevent them from affecting ProGuard's +# optimization run. +-keep @interface **.AccessedByNative +-keep @interface **.CalledByNative +-keep @interface **.CalledByNativeUnchecked +-keep @interface **.RemovableInRelease +-keep @interface **.UsedByReflection # Keep the factory and its public members; it's the main entry point used by the # framework. @@ -39,11 +43,19 @@ native ; } -# Keep things explicitly marked as used by reflection +# Keep classes marked as used by reflection +-keep @**.UsedByReflection class com.android.webview.chromium.**,org.chromium.** + +# Keep members explicitly marked as used by reflection -keepclasseswithmembers class com.android.webview.chromium.**,org.chromium.** { @**.UsedByReflection *; } +# Remove methods annotated with this if their return value is unused +-assumenosideeffects class ** { + @org.chromium.base.annotations.RemovableInRelease ; +} + # Linker dynamically casts to $TestRunner when running tests. We don't run these # tests in WebView. -dontnote org.chromium.base.library_loader.Linker$TestRunner