flutter release build crashes on launch only on some samsung phones, debug is fine
Tunde Adebayo@tunde_ade
abeg help, this one is killing me. app works perfectly in debug and profile on all our test phones. the release build from the play store crashes immediately on launch on some samsung A series phones (android 11 and 12). not all of them
what i've tried:
- flutter clean, rebuilt, same thing
- crashlytics shows a native stack trace with obfuscated names, something like a ClassNotFoundException deep inside a plugin
- bumped all plugins to latest, no change
flutter build appbundle --release --obfuscate --split-debug-info=build/symbols
it started after we added a new payments SDK plugin. i suspect R8/proguard but i dont know how to prove it
Accepted answer
I am iOS person but our Android team had the same thing. ClassNotFoundException only in release is almost always R8 removing a class that the SDK loads by reflection. Only some phones because the SDK takes a different code path depending on the device.
To prove it: make one release build with minify disabled in android/app/build.gradle (minifyEnabled false in the release buildType). If the crash disappears, it is R8.
Then add keep rules for the SDK package in android/app/proguard-rules.pro (the SDK docs usually list them), for example:
-keep class com.vendor.payments.** { *; }
and turn minify back on.
Written by
Tunde Adebayo
Mobile dev (Flutter + React Native) at an agency in Lagos. building fintech and logistics apps mostly. if your app is slow on a 2GB android phone, its not "fine". football on weekends
Get the best of #thumb_zone weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to commentAccepted answer
Yuki Tanaka@yuki_ios
I am iOS person but our Android team had the same thing. ClassNotFoundException only in release is almost always R8 removing a class that the SDK loads by reflection. Only some phones because the SDK takes a different code path depending on the device.
To prove it: make one release build with minify disabled in android/app/build.gradle (minifyEnabled false in the release buildType). If the crash disappears, it is R8.
Then add keep rules for the SDK package in android/app/proguard-rules.pro (the SDK docs usually list them), for example:
-keep class com.vendor.payments.** { *; }
and turn minify back on.
Tunde Adebayo@tunde_ade
IT WAS R8. one build with minify off, crash gone. the keep rules were hidden in the sdk FAQ, not in the setup guide 🙄 added them, minify back on, works on all the samsungs. yuki thank you
Jake Morrison@jakemakesgames
an ios dev saving an android app in tunde's own topic. you're never living this down mate
Marcus Johnson@marcus_oncall
also upload those symbols to crashlytics so the stack traces are readable next time. the split-debug-info folder isnt doing anything sitting on your laptop