Flutter release-apk crashes as soon as I open the app with a GSON error
[ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)] java.lang.AssertionError: AssertionError (GSON 2.8.5): java.lang.NoSuchFieldException: UNKNOWN
E/flutter (14343): at com.google.a.f.a(Unknown Source)
E/flutter (14343): at com.google.a.f.a(Unknown Source)
E/flutter (14343): at com.google.a.f.a(Unknown Source)
E/flutter (14343): at com.b.a.b.a$a.b(Unknown Source)
E/flutter (14343): at com.b.a.a.onMethodCall(Unknown Source)
E/flutter (14343): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source)
E/flutter (14343): at io.flutter.view.FlutterNativeView.handlePlatformMessage(Unknown Source)
E/flutter (14343): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (14343): at android.os.MessageQueue.next(MessageQueue.java:143)
E/flutter (14343): at android.os.Looper.loop(Looper.java:130)
E/flutter (14343): at android.app.ActivityThread.main(ActivityThread.java:6117)
E/flutter (14343): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (14343): at java.lang.reflect.Method.invoke(Method.java:372)
E/flutter (14343): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
E/flutter (14343): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
E/flutter (14343): Caused by: java.lang.AssertionError: java.lang.NoSuchFieldException: UNKNOWN
E/flutter (14343): at com.google.a.b.a.n$a.
E/flutter (14343): at com.google.a.b.a.n$24.a(Unknown Source)
E/flutter (14343): at com.google.a.f.a(Unknown Source)
E/flutter (14343): at com.google.a.b.a.a$1.a(Unknown Source)
E/flutter (14343): at com.google.a.f.a(Unknown Source)
E/flutter (14343): ... 15 more
E/flutter (14343): Caused by: java.lang.NoSuchFieldException: UNKNOWN
E/flutter (14343): at java.lang.Class.getField(Class.java:1104)
E/flutter (14343): ... 20 more
E/flutter (14343):
F/flutter (14343): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)] Check failed: CheckException(env).
It's not clear why this is a Gson problem. It looks like obfuscation removed a field. Can you provide a self-contained sample that fails and demonstrates that Gson has a bug?
@JakeWharton I honestly do not know the steps to reproduce this error. It popped up whilst installing my release apk in Flutter and it explicitly states java.lang.AssertionError: AssertionError (GSON 2.8.5): so i decided to report it here
I figured the culprit here. It happens when minifyEnabled is set to true. So just disable it and it should fix
I commented these on my app/build.gradle and now works
buildTypes {
release {
.........
minifyEnabled false // set this to false to prevent java.lang.NoSuchFieldException
You saved me a lot of headaches, @nemoryoliver !
Thanks!!
I can feel you @burkard . So happy I've helped. You're welcome
FYI, you are disabling your proguard!! be careful!
Add the below in proguard-rules.pro, it will be fixed!
-keepclassmembers enum * {*;}
I seem to have solved this with flutter build apk --no-shrink ...
My build wasn't using proguard/minifyEnabled, and strangely my APK was crashing on an Android 7 device, but not on an Android 9 device..
Thanks for your help!You exactly saved me.
do we have another alternative to use shrink
Probably same issue as #924
Most helpful comment
Add the below in proguard-rules.pro, it will be fixed!