我编写了一个混合应用程序,它使用react-native-svg在反应原生视图中呈现svg图像。 一切都很完美。今天,当我为我的应用程序创建release apk并将其部署到模拟器时,它崩溃了一个错误:
E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.example.packagname, PID: 8574
java.lang.IllegalStateException: java.lang.NoSuchFieldException: mFill
at com.horcrux.svg.q.a(Unknown Source:78)
at com.horcrux.svg.i$1.a(Unknown Source:9)
at com.horcrux.svg.aa.a(Unknown Source:22)
at com.horcrux.svg.i.b(Unknown Source:14)
at com.horcrux.svg.i.a(Unknown Source:10)
at com.horcrux.svg.t.a(Unknown Source:104)
at com.horcrux.svg.t.c(Unknown Source:25)
at com.horcrux.svg.t.a(Unknown Source:7)
at com.facebook.react.uimanager.u.a(Unknown Source:5)
at com.facebook.react.uimanager.ag.a(Unknown Source:56)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.d(Unknown Source:83)
at com.facebook.react.uimanager.ag.e(Unknown Source:17)
at com.facebook.react.uimanager.UIManagerModule.onBatchComplete(Unknown Source:27)
at com.facebook.react.bridge.z.d(Unknown Source:30)
at com.facebook.react.bridge.CatalystInstanceImpl$a.onBatchComplete(Unknown Source:14)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.a.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(Unknown Source:16)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoSuchFieldException: mFill
at java.lang.Class.getField(Class.java:1601)
at com.horcrux.svg.q.a(Unknown Source:41)
at com.horcrux.svg.i$1.a(Unknown Source:9)
at com.horcrux.svg.aa.a(Unknown Source:22)
at com.horcrux.svg.i.b(Unknown Source:14)
at com.horcrux.svg.i.a(Unknown Source:10)
at com.horcrux.svg.t.a(Unknown Source:104)
at com.horcrux.svg.t.c(Unknown Source:25)
at com.horcrux.svg.t.a(Unknown Source:7)
at com.facebook.react.uimanager.u.a(Unknown Source:5)
at com.facebook.react.uimanager.ag.a(Unknown Source:56)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.a(Unknown Source:34)
at com.facebook.react.uimanager.ag.d(Unknown Source:83)
at com.facebook.react.uimanager.ag.e(Unknown Source:17)
at com.facebook.react.uimanager.UIManagerModule.onBatchComplete(Unknown Source:27)
at com.facebook.react.bridge.z.d(Unknown Source:30)
at com.facebook.react.bridge.CatalystInstanceImpl$a.onBatchComplete(Unknown Source:14)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.a.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(Unknown Source:16)
at java.lang.Thread.run(Thread.java:764)
只有当我从proguard-rule.pro文件中评论-dontobfuscate
时才会看到此问题。我想混淆我的apk代码(我无法控制它。)。
我正在使用类似于本例中所示的proguard文件,
https://github.com/magicismight/react-native-svg-example/blob/cfb788461efae0de367c97aadcc829cdeb959a8d/android/app/proguard-rules.pro
还有其他人遇到过这个问题吗?有任何建议,如何在proguard-rules文件中启用-dontobfuscate时停止我的应用程序崩溃?
编辑我对Android开发很新,我第一次尝试proguard。关于如何调试此类问题的任何积极建议都将非常有用。
答案 0 :(得分:2)
这是进展。它需要耐心和眼泪:))
在您的堆栈跟踪中,您可以轻松地看到您尝试通过反射访问mField。任何正在使用的行 反射必须添加到proguard异常。
你为什么这么问?因为它的名称会被更改,因此Class
方法无法找到它。
答案 1 :(得分:2)
问题与proguard有关。正如自述文件(或this issue)中所述,您需要在android/app/proguard-rules.pro
文件中添加以下行:
-keep public class com.horcrux.svg.** {*;}