flutter_image_cropper icon indicating copy to clipboard operation
flutter_image_cropper copied to clipboard

`NullPointerException` in `UCropActivity` during `onCreateOptionsMenu()` causing crash in release mode

Open mbfakourii opened this issue 1 year ago • 18 comments

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

mbfakourii avatar Dec 22 '24 10:12 mbfakourii

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 avatar Dec 22 '24 10:12 mbfakourii

@mbfakourii works for me too. We had the same problem in production and I needed a quick fix, thanks.

GuimG avatar Dec 27 '24 07:12 GuimG

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.

PisethChuon avatar Dec 27 '24 09:12 PisethChuon

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 avatar Dec 27 '24 10:12 hnvn

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.

mbfakourii avatar Dec 27 '24 17:12 mbfakourii

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.

inpt333 avatar Jan 06 '25 11:01 inpt333

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 avatar Jan 31 '25 08:01 vinay-elred

@vinay-elred just tried the proguard rules now, unfortunately it doesn't solve it

0x3dev avatar Feb 02 '25 13:02 0x3dev

Still an issue.

MrLightful avatar Feb 04 '25 09:02 MrLightful

sad to see that still this issue has not been resolved only working with debug mode not release.

fullflash avatar Feb 25 '25 00:02 fullflash

Just ran into this in March of 2025 on version 9.0.0. The fix described above worked for me 👍

nfriend avatar Mar 05 '25 15:03 nfriend

April 2025 and still an issue.

rahdeva avatar Apr 17 '25 00:04 rahdeva

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

rahdeva avatar Apr 17 '25 09:04 rahdeva

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

DmitryKamynin avatar May 11 '25 20:05 DmitryKamynin

Adding the following to the proguard-rules.pro file solved my issue

-dontwarn org.xmlpull.v1.**
-keep class org.xmlpull.v1.** { *; }

json-kim avatar Jul 09 '25 07:07 json-kim

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:

Used above as a temporary solution. @hnvn Any outlook on a fix?

yizaho avatar Jul 22 '25 07:07 yizaho

The same problem

lincolnmedicinadireta avatar Aug 01 '25 19:08 lincolnmedicinadireta

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 )

inkyu0103 avatar Aug 27 '25 07:08 inkyu0103