From 22c99f42b37425bd9ee6a0652e3797b174409c40 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Tue, 20 Mar 2018 16:56:20 +0800 Subject: [PATCH 1/2] inline and fix proguard rules --- ReactAndroid/build.gradle | 2 + ReactAndroid/proguard-rules.pro | 71 ++++++++++++++++++ .../HelloWorld/android/app/proguard-rules.pro | 72 ------------------- 3 files changed, 73 insertions(+), 72 deletions(-) create mode 100644 ReactAndroid/proguard-rules.pro diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index fa1be07afa74a2..15b5c02cdcab7d 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -251,6 +251,8 @@ android { versionCode 1 versionName "1.0" + consumerProguardFiles 'proguard-rules.pro' + ndk { moduleName "reactnativejni" } diff --git a/ReactAndroid/proguard-rules.pro b/ReactAndroid/proguard-rules.pro new file mode 100644 index 00000000000000..668d5bd472f8de --- /dev/null +++ b/ReactAndroid/proguard-rules.pro @@ -0,0 +1,71 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Disabling obfuscation is useful if you collect stack traces from production crashes +# (unless you are using a system that supports de-obfuscate the stack traces). +# -dontobfuscate + +# React Native + +# Keep our interfaces so they can be used by other ProGuard rules. +# See http://sourceforge.net/p/proguard/bugs/466/ +-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip +-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters +-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip + +# Do not strip any method/class that is annotated with @DoNotStrip +-keep @com.facebook.proguard.annotations.DoNotStrip class * +-keep @com.facebook.common.internal.DoNotStrip class * +-keepclassmembers class * { + @com.facebook.proguard.annotations.DoNotStrip *; + @com.facebook.common.internal.DoNotStrip *; +} + +-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { + void set*(***); + *** get*(); +} + +-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } +-keep class * extends com.facebook.react.bridge.NativeModule { *; } +-keepclassmembers,includedescriptorclasses class * { native ; } +-keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } +-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } +-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } + +-dontwarn com.facebook.react.** +-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; } + +# TextLayoutBuilder uses a non-public Android constructor within StaticLayout. +# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. +-dontwarn android.text.StaticLayout + +# okhttp + +-keepattributes Signature +-keepattributes *Annotation* +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-dontwarn okhttp3.** + +# okio + +-keep class sun.misc.Unsafe { *; } +-dontwarn java.nio.file.* +-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement +-dontwarn okio.** diff --git a/local-cli/templates/HelloWorld/android/app/proguard-rules.pro b/local-cli/templates/HelloWorld/android/app/proguard-rules.pro index b30112461f0e74..a92fa177ee49f0 100644 --- a/local-cli/templates/HelloWorld/android/app/proguard-rules.pro +++ b/local-cli/templates/HelloWorld/android/app/proguard-rules.pro @@ -15,75 +15,3 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} - -# Disabling obfuscation is useful if you collect stack traces from production crashes -# (unless you are using a system that supports de-obfuscate the stack traces). -# -dontobfuscate - -# React Native - -# Keep our interfaces so they can be used by other ProGuard rules. -# See http://sourceforge.net/p/proguard/bugs/466/ --keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip --keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters --keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip - -# Do not strip any method/class that is annotated with @DoNotStrip --keep @com.facebook.proguard.annotations.DoNotStrip class * --keep @com.facebook.common.internal.DoNotStrip class * --keepclassmembers class * { - @com.facebook.proguard.annotations.DoNotStrip *; - @com.facebook.common.internal.DoNotStrip *; -} - --keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { - void set*(***); - *** get*(); -} - --keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } --keep class * extends com.facebook.react.bridge.NativeModule { *; } --keepclassmembers,includedescriptorclasses class * { native ; } --keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } --keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } --keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } - --dontwarn com.facebook.react.** - -# TextLayoutBuilder uses a non-public Android constructor within StaticLayout. -# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. --dontwarn android.text.StaticLayout - -# Fresco -# Keep our interfaces so they can be used by other ProGuard rules. -# See http://sourceforge.net/p/proguard/bugs/466/ --keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize - -# Do not strip any method/class that is annotated with @DoNotOptimize --keep @com.facebook.soloader.DoNotOptimize class * --keepclassmembers class * { - @com.facebook.soloader.DoNotOptimize *; -} - -# Keep native methods --keepclassmembers class * { - native ; -} - --dontwarn javax.annotation.** --dontwarn com.facebook.infer.** - -# okhttp - --keepattributes Signature --keepattributes *Annotation* --keep class okhttp3.** { *; } --keep interface okhttp3.** { *; } --dontwarn okhttp3.** - -# okio - --keep class sun.misc.Unsafe { *; } --dontwarn java.nio.file.* --dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement --dontwarn okio.** From 5e4be6e098e1a1a830d71141a273ae95ad49bf7e Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Fri, 30 Mar 2018 22:31:39 +0800 Subject: [PATCH 2/2] migrate fresco proguard rules --- ReactAndroid/proguard-rules.pro | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ReactAndroid/proguard-rules.pro b/ReactAndroid/proguard-rules.pro index 668d5bd472f8de..6e9ff0ac75515f 100644 --- a/ReactAndroid/proguard-rules.pro +++ b/ReactAndroid/proguard-rules.pro @@ -69,3 +69,22 @@ -dontwarn java.nio.file.* -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn okio.** + +# Fresco +# Keep our interfaces so they can be used by other ProGuard rules. +# See http://sourceforge.net/p/proguard/bugs/466/ +-keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize + +# Do not strip any method/class that is annotated with @DoNotOptimize +-keep @com.facebook.soloader.DoNotOptimize class * +-keepclassmembers class * { + @com.facebook.soloader.DoNotOptimize *; +} + +# Keep native methods +-keepclassmembers class * { + native ; +} + +-dontwarn javax.annotation.** +-dontwarn com.facebook.infer.**