bsc*_*han 5 react-native android-proguard
当我在现有的 Android 应用程序中使用该-dontobfuscate选项并使用单个 React Native 屏幕时,发布版本工作正常。
(我还必须从 https://github.com/facebook/react-native/blob/master/local-cli/generator-android/templates/src/app/proguard-rules 为 proguard 设置反应本机配置。亲)
但是,我想混淆我现有的应用程序并仅忽略react-native混淆(因为它不受支持: https: //github.com/facebook/react-native/issues/7530)
注释掉后-dontobfuscate,我收到以下错误:
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
...
Run Code Online (Sandbox Code Playgroud)
我尝试了以下配置,但没有一个起作用。它们要么在 Proguard 阶段抛出警告assembleRelease,要么一旦构建,在首次启动 React Native 屏幕时抛出异常。
第一次配置尝试:
-keep class com.facebook.react.** { public protected private *; }
Run Code Online (Sandbox Code Playgroud)第二次配置尝试:
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
Run Code Online (Sandbox Code Playgroud)第三次配置尝试:
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
Run Code Online (Sandbox Code Playgroud)第四个配置尝试:
support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
Run Code Online (Sandbox Code Playgroud)例外情况如:
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)
Run Code Online (Sandbox Code Playgroud)
任何有使用react-native的工作版本apk(现有的android应用程序)的人,你能分享一下你的proguard配置吗?
这是一个使 ReactNative 0.27.2 版本正常工作的工作配置。(照顾本机模块)。
大多数示例和react-native init 项目都具有如下列出的react native 设置。2 个更改是 - 1. 删除 dontobfuscate 和 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.**
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8325 次 |
| 最近记录: |