Skip to content

Commit 9b9b6c8

Browse files
gengjiawenfacebook-github-bot
authored andcommitted
Inline and fix proguard rules
Summary: The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project. <!-- Required: Write your motivation here. If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged. --> Use RNTester to build the release flavor (now it has bugs #18460, I keep my change in local for now), after build success, run to check if crash. In the process, I also fix #12994 and #6624 by adding the following to proguard rules ```proguard -keep,includedescriptorclasses class com.facebook.react.bridge.** { *; } ``` <!-- Does this PR require a documentation change? Create a PR at https://github.com/facebook/react-native-website and add a link to it here. --> [ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules . <!-- **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [ {Component} ] [ INTERNAL ] [ ENHANCEMENT ] [ {Filename} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> Closes #18461 Differential Revision: D7527533 Pulled By: hramos fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
1 parent 7a29ad1 commit 9b9b6c8

File tree

3 files changed

+92
-72
lines changed

3 files changed

+92
-72
lines changed

ReactAndroid/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ android {
251251
versionCode 1
252252
versionName "1.0"
253253

254+
consumerProguardFiles 'proguard-rules.pro'
255+
254256
ndk {
255257
moduleName "reactnativejni"
256258
}

ReactAndroid/proguard-rules.pro

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Disabling obfuscation is useful if you collect stack traces from production crashes
20+
# (unless you are using a system that supports de-obfuscate the stack traces).
21+
# -dontobfuscate
22+
23+
# React Native
24+
25+
# Keep our interfaces so they can be used by other ProGuard rules.
26+
# See http://sourceforge.net/p/proguard/bugs/466/
27+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29+
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30+
31+
# Do not strip any method/class that is annotated with @DoNotStrip
32+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
33+
-keep @com.facebook.common.internal.DoNotStrip class *
34+
-keepclassmembers class * {
35+
@com.facebook.proguard.annotations.DoNotStrip *;
36+
@com.facebook.common.internal.DoNotStrip *;
37+
}
38+
39+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40+
void set*(***);
41+
*** get*();
42+
}
43+
44+
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45+
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
46+
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
47+
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
48+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
49+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
50+
51+
-dontwarn com.facebook.react.**
52+
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
53+
54+
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
55+
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
56+
-dontwarn android.text.StaticLayout
57+
58+
# okhttp
59+
60+
-keepattributes Signature
61+
-keepattributes *Annotation*
62+
-keep class okhttp3.** { *; }
63+
-keep interface okhttp3.** { *; }
64+
-dontwarn okhttp3.**
65+
66+
# okio
67+
68+
-keep class sun.misc.Unsafe { *; }
69+
-dontwarn java.nio.file.*
70+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
71+
-dontwarn okio.**
72+
73+
# Fresco
74+
# Keep our interfaces so they can be used by other ProGuard rules.
75+
# See http://sourceforge.net/p/proguard/bugs/466/
76+
-keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize
77+
78+
# Do not strip any method/class that is annotated with @DoNotOptimize
79+
-keep @com.facebook.soloader.DoNotOptimize class *
80+
-keepclassmembers class * {
81+
@com.facebook.soloader.DoNotOptimize *;
82+
}
83+
84+
# Keep native methods
85+
-keepclassmembers class * {
86+
native <methods>;
87+
}
88+
89+
-dontwarn javax.annotation.**
90+
-dontwarn com.facebook.infer.**

local-cli/templates/HelloWorld/android/app/proguard-rules.pro

-72
Original file line numberDiff line numberDiff line change
@@ -15,75 +15,3 @@
1515
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
1616
# public *;
1717
#}
18-
19-
# Disabling obfuscation is useful if you collect stack traces from production crashes
20-
# (unless you are using a system that supports de-obfuscate the stack traces).
21-
# -dontobfuscate
22-
23-
# React Native
24-
25-
# Keep our interfaces so they can be used by other ProGuard rules.
26-
# See http://sourceforge.net/p/proguard/bugs/466/
27-
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28-
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29-
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30-
31-
# Do not strip any method/class that is annotated with @DoNotStrip
32-
-keep @com.facebook.proguard.annotations.DoNotStrip class *
33-
-keep @com.facebook.common.internal.DoNotStrip class *
34-
-keepclassmembers class * {
35-
@com.facebook.proguard.annotations.DoNotStrip *;
36-
@com.facebook.common.internal.DoNotStrip *;
37-
}
38-
39-
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40-
void set*(***);
41-
*** get*();
42-
}
43-
44-
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45-
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
46-
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
47-
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
48-
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
49-
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
50-
51-
-dontwarn com.facebook.react.**
52-
53-
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
54-
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
55-
-dontwarn android.text.StaticLayout
56-
57-
# Fresco
58-
# Keep our interfaces so they can be used by other ProGuard rules.
59-
# See http://sourceforge.net/p/proguard/bugs/466/
60-
-keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize
61-
62-
# Do not strip any method/class that is annotated with @DoNotOptimize
63-
-keep @com.facebook.soloader.DoNotOptimize class *
64-
-keepclassmembers class * {
65-
@com.facebook.soloader.DoNotOptimize *;
66-
}
67-
68-
# Keep native methods
69-
-keepclassmembers class * {
70-
native <methods>;
71-
}
72-
73-
-dontwarn javax.annotation.**
74-
-dontwarn com.facebook.infer.**
75-
76-
# okhttp
77-
78-
-keepattributes Signature
79-
-keepattributes *Annotation*
80-
-keep class okhttp3.** { *; }
81-
-keep interface okhttp3.** { *; }
82-
-dontwarn okhttp3.**
83-
84-
# okio
85-
86-
-keep class sun.misc.Unsafe { *; }
87-
-dontwarn java.nio.file.*
88-
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
89-
-dontwarn okio.**

0 commit comments

Comments
 (0)