If you are using image_picker
plugin in flutter and recently upgraded Android Gradle Plugin to 4.0.0 then you may face crash on launch in release mode. Actually this problem is due to code shrinking in latest version, which is shrinking code of java/kotlin code of your project. And after this update code of androidx.lifecycle
getting shrinked which is being used by image_picker
library.
Thats why our app is getting crashed after this update.
Add proguard rules inside android project, you can find proguard-rules file at following location android/app/proguard-rules.pro
. And add below code at the bottom of proguard-rules.pro
file.
-keep class androidx.lifecycle.** { *; }
Now try to build your app in release mode. And now you app will not crash. If after adding above line your build fail with following error:
Execution failed for task ':app:lintVitalRelease'.> Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'.
Then don’t worry about it, we can disable lintcheck for release build. To do this open this file android/app/build.gradle
. and add below lines inside android node.
lintOptions {checkReleaseBuilds false}
Now you will not get any error while creating release build.
Another way to fix stratup crash is by downgrading Android Gradle Plugin to 3.6.2, and it will start working as before. To do this make changes in following file android/build.gradle
. and change following lines:
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:3.6.2'
Now try to build your app in release mode. And now you app will not crash.
Last option to fix this crash is build without shrking code. To do this we don’t need to change inside our code. We can simply do this from commandline. Do like below:
flutter build appbundle
flutter build appbundle --no-shrink
So by adding --no-shrink
in commandline will tell the compiler to not shrink the code while generating release appBundle.
LESSONS
COURSES
TUTORS
Quick Links
Legal Stuff
Social Media