Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native android app crashes with in release apk

I have written one hybrid app which is using react-native-svg to render svg images in react-native views. Everything works perfectly. Today, When I created release apk for my app and deployed it to an emulator it crashed with an error:

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) 

I see this problem only when I comment -dontobfuscate from the proguard-rule.pro file. I want to obfuscate my apk code(I can't control it.). I am using proguard file similar to the one shown in this example, https://github.com/magicismight/react-native-svg-example/blob/cfb788461efae0de367c97aadcc829cdeb959a8d/android/app/proguard-rules.pro

Has anyone else faced this issue? Any suggestion on , how can I stop my app from crashing without enabling -dontobfuscate in proguard-rules file?

Edit I am pretty new to android development and I am trying proguard for the first time. Any positive suggestions on how to debug such issues will be really helpful.

like image 907
ggsrivas Avatar asked Oct 16 '17 06:10

ggsrivas


People also ask

How do I stop my React Native app from crashing?

Force stop the app. The easiest way to fix an app that keeps crashing on your Android smartphone is to simply force stop it and open it again. Restart the device. Reinstall the app.

Why does my APK keep crashing?

You may have downloaded the app improperly, and all you need to do is to reinstall the app to fix the crashing problem: Go to Settings > “Apps” or “Application manager” > Choose the app that crashes > Tap the “Uninstall” option to make it. Then you can go to Google Play Store to reinstall the app after a few minutes.

Does Android studio support react?

You will need Node, the React Native command line interface, a JDK, and Android Studio. While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android.


2 Answers

The problem is related to proguard. As is now stated in the readme (or this issue), you need to add the following line to your android/app/proguard-rules.pro file:

-keep public class com.horcrux.svg.** {*;}
like image 175
David Schumann Avatar answered Sep 23 '22 08:09

David Schumann


This is proguard. It needs patience and tears :)

In your stacktrace easily can be see that you are trying to access mField by reflection. Any line that is using by reflection must be add to proguard exception.

Why you ask? Because it name will be changed so Class methods can't find it.

like image 37
Karol Kulbaka Avatar answered Sep 19 '22 08:09

Karol Kulbaka