`NullPointerException` in `UCropActivity` during `onCreateOptionsMenu()` causing crash in release mode
Description
The app crashes with a NullPointerException in the UCropActivity during the onCreateOptionsMenu() method, but only in release mode. This issue does not occur in debug mode.
FATAL EXCEPTION: main
Process: com.example.app, PID: 4046
java.lang.NullPointerException: throw with null exception
at m.i.inflate(SourceFile:25)
at com.yalantis.ucrop.UCropActivity.onCreateOptionsMenu(SourceFile:7)
at android.app.Activity.onCreatePanelMenu(Activity.java:4228)
at e.n.onCreatePanelMenu(SourceFile:3)
at j.y.onCreatePanelMenu(SourceFile:11)
at e.j.run(SourceFile:925)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Additional Information settings.gradle:
id "com.android.application" version "8.2.1" apply false
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
Other:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.26100.2454], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
[√] Android Studio (version 2024.2)
[√] Connected device (5 available)
[√] Network resources
app/build.gradle:
buildTypes {
release {
minifyEnabled false
shrinkResources false
signingConfig signingConfigs.release
}
}
I solved the problem with this code, but the program size increased by 7 MB!
@mbfakourii works for me too. We had the same problem in production and I needed a quick fix, thanks.
Add the UCropActivity to your Android projects AndroidManifest.xml file.
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:theme="@style/Theme.AppCompat.NoActionBar" />
Open android/app/src/main/AndroidManifest.xml.
It works for me. This specifies the UCropActivity class that handles the image cropping.
add following lines to your android/app/proguard-rules.pro:
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
Fyi why it happened? https://developer.android.com/build/shrink-code
add following lines to your
android/app/proguard-rules.pro:-dontwarn com.yalantis.ucrop** -keep class com.yalantis.ucrop** { *; } -keep interface com.yalantis.ucrop** { *; }Fyi why it happened? https://developer.android.com/build/shrink-code
I tested it and it didn't work.
add following lines to your
android/app/proguard-rules.pro:-dontwarn com.yalantis.ucrop** -keep class com.yalantis.ucrop** { *; } -keep interface com.yalantis.ucrop** { *; }Fyi why it happened? https://developer.android.com/build/shrink-code
@hnvn it seems that those are not enough, it didn't work for me either.
Using this : Working for me now https://github.com/hnvn/flutter_image_cropper/issues/544#issuecomment-2558412236
@hnvn Can you please confirm by when can except this fix.
@vinay-elred just tried the proguard rules now, unfortunately it doesn't solve it
Still an issue.
sad to see that still this issue has not been resolved only working with debug mode not release.
Just ran into this in March of 2025 on version 9.0.0. The fix described above worked for me 👍
April 2025 and still an issue.
Changing the following line in gradle.properties works for me:
android.enableR8.fullMode=false
This is better than disabling minification and resource shrinking completely, so I still keep these set to true:
minifyEnabled true
shrinkResources true
But please fix this issue @hnvn
This may sound crazy, but I accidentally discovered a strange pattern.
After 8 hours of work, I opened pubspec.yaml to remove unnecessary dependencies, and the app stopped opening in production.
I soon discovered that if I remove the emoji_picker_flutter dependency, but leave flutter_image_cropper alone, I magically get the same error on startup as the issue author
Maybe the problem is something completely different, and this won't work for others
I will certainly try to find another way to solve this problem, because leaving it like this is shooting myself in the foot in the future
Adding the following to the proguard-rules.pro file solved my issue
-dontwarn org.xmlpull.v1.**
-keep class org.xmlpull.v1.** { *; }
Changing the following line in
gradle.propertiesworks for me:
android.enableR8.fullMode=falseThis is better than disabling minification and resource shrinking completely, so I still keep these set totrue:
Used above as a temporary solution. @hnvn Any outlook on a fix?
The same problem
Adding the following to the proguard-rules.pro file solved my issue
-dontwarn org.xmlpull.v1.** -keep class org.xmlpull.v1.** { *; }
It works for me!
Android 15 ( SDK 35 )