android-demo-app
android-demo-app copied to clipboard
Flutter App crashed in release version only
Debug version works fine. But the same release version crashed on module = LiteModuleLoader.load(absPath); in MainActivity.java with errors:
E/AndroidRuntime(15751): FATAL EXCEPTION: main
E/AndroidRuntime(15751): Process: com.example.pyml, PID: 15751
E/AndroidRuntime(15751): java.lang.ExceptionInInitializerError
E/AndroidRuntime(15751): at org.pytorch.c.a(Unknown Source:2)
E/AndroidRuntime(15751): at com.example.pyml.MainActivity.P(Unknown Source:234)
E/AndroidRuntime(15751): at com.example.pyml.MainActivity.O(Unknown Source:0)
E/AndroidRuntime(15751): at i.a.a(Unknown Source:2)
E/AndroidRuntime(15751): at x.j$a.a(Unknown Source:17)
E/AndroidRuntime(15751): at l.c.k(Unknown Source:18)
E/AndroidRuntime(15751): at l.c.l(Unknown Source:20)
E/AndroidRuntime(15751): at l.c.h(Unknown Source:0)
E/AndroidRuntime(15751): at l.b.run(Unknown Source:12)
E/AndroidRuntime(15751): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(15751): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15751): at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(15751): at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(15751): at android.app.ActivityThread.main(ActivityThread.java:8669)
E/AndroidRuntime(15751): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(15751): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(15751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/AndroidRuntime(15751): Caused by: java.lang.ClassNotFoundException: org.pytorch.PyTorchAndroid
E/AndroidRuntime(15751): at java.lang.Runtime.nativeLoad(Native Method)
E/AndroidRuntime(15751): at java.lang.Runtime.nativeLoad(Runtime.java:1121)
E/AndroidRuntime(15751): at java.lang.Runtime.loadLibrary0(Runtime.java:1075)
E/AndroidRuntime(15751): at java.lang.Runtime.loadLibrary0(Runtime.java:998)
E/AndroidRuntime(15751): at java.lang.System.loadLibrary(System.java:1661)
E/AndroidRuntime(15751): at j.c.a(Unknown Source:0)
E/AndroidRuntime(15751): at j.a.c(Unknown Source:8)
E/AndroidRuntime(15751): at org.pytorch.LiteNativePeer.<clinit>(Unknown Source:16)
E/AndroidRuntime(15751): ... 17 more
Tried many org.pytorch:pytorch_android_lite versions - result always the same. Attaching the full and minimal Flutter project to reproduce the issue (24 Mb, model included). First try on debug - you'll receive "ML: SUCCESS" message on button press. Then on Release - app will instantly closes on loading the model.
the same, did you solve it? I found that changing minifyEnabled to false works, but it's not a good solution
@COO1M Unfortunately nope. Instead started to learn native Android/Java development in order to make desired ML based app. Surprisingly, even after Flutter simplicity I just love to work now in Android Studio and code in java. Almost all examples here works great after that.
Not Flutter, my problem happens in native Android, and now it has been solved. As I guessed, something was obfuscated by ProGuard. Since I didn't find the official proguard rules of Pytorch_Android, I added -keep class org.pytorch.** {*;}
-keep class com.facebook.** {*;}
, it worked.
Git it, thank you for solution!