带有混淆功能的带有React Native的Android App是否有适用的Proguard配置? [英] Any working Proguard Configuration for Android App with React Native with obfuscation?
问题描述
当我在现有的Android应用中使用一个单一的React Native屏幕使用-dontobfuscate
选项时,发布版本就可以正常工作.
When I use the -dontobfuscate
option in my existing android app with a single React Native screen, release build works fine.
(我还必须从但是,我想混淆我现有的应用程序,而只忽略react-native混淆(因为不支持它: https://github.com/facebook/react-native/issues/7530 )
However, I want to obfuscate my existing app and ignore react-native obfuscation only (since it's not supported as per : https://github.com/facebook/react-native/issues/7530)
将-dontobfuscate
注释掉后,出现以下错误:
After commenting out -dontobfuscate
, I got these errors:
Warning: com.facebook.react.views.recyclerview.NotAnimatedItemAnimator: can't find referenced method 'void dispatchRemoveStarting(android.support.v7.widget.RecyclerView$ViewHolder)' in program class com.facebook.react.views.recyclerview.NotAnimatedItemAnimator
Warning: com.facebook.react.views.recyclerview.NotAnimatedItemAnimator: can't find referenced method 'void dispatchRemoveFinished(android.support.v7.widget.RecyclerView$ViewHolder)' in program class com.facebook.react.views.recyclerview.NotAnimatedItemAnimator
...
我尝试了以下配置,但它们都不起作用.它们要么在assembleRelease
的保护阶段期间发出警告,要么在构建后就发出警告,在第一次启动react native屏幕时引发异常.
I tried below configurations and NONE of them work. They either throw warnings during proguard phase of assembleRelease
or once built, throws exception on first launch of react native screen.
-
首次配置尝试:
First Config Try:
-keep class com.facebook.react.** { public protected private *; }
第二个配置尝试:
Second Config Try:
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
第三种配置尝试:
Third config try:
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
第四次配置尝试:
Fourth config Try:
support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
异常,例如:
Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule' (declaration of 'com.facebook.react.modules.netinfo.NetInfoModule' appears in /data/app/com.sampleapp-1/base.apk)
at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)
任何人都可以使用带有react-native的apk(现有的android应用)发布,您能否分享您的proguard配置?
Anyone with working release apk (Existing android app) with react-native, can you please share your proguard configurations?
推荐答案
这是一个使ReactNative 0.27.2版本能够正常工作的配置. (照顾本机模块).
Here is a working configuration to make things work with ReactNative 0.27.2 version. (Takes care of native modules).
大多数样本和react-native init项目的反应本机设置如下所示. 2个更改是- 1.删除dontobfuscate,然后 2. -keep类com.facebook.** {*; }
Most of the samples and the react-native init projects have the react native settings as listed below. 2 Changes are - 1. remove dontobfuscate and 2. -keep class com.facebook.** { *; }
#-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 <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
-keep class com.facebook.** { *; }
-dontwarn com.facebook.react.**
# 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.**
这篇关于带有混淆功能的带有React Native的Android App是否有适用的Proguard配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!