Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[image_picker] crash when start #48622

Closed
riyanWi opened this issue Jan 11, 2020 · 19 comments · Fixed by flutter/plugins#2467
Closed

[image_picker] crash when start #48622

riyanWi opened this issue Jan 11, 2020 · 19 comments · Fixed by flutter/plugins#2467
Assignees
Labels
c: crash Stack traces logged to the console p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android t: shrink The "--shrink" feature of the Flutter tool waiting for PR to land (fixed) A fix is in flight
Milestone

Comments

@riyanWi
Copy link

riyanWi commented Jan 11, 2020

I have a trouble when I am using image_picker 0.6.3, my app always crash when developing but can run when debug.
This is crash log

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trj.rdctracker/com.trj.rdctracker.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.f.a(androidx.lifecycle.g)' on a null object reference
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2977)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3114)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:201)
	at android.app.ActivityThread.main(ActivityThread.java:6831)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.f.a(androidx.lifecycle.g)' on a null object reference
	at io.flutter.plugins.imagepicker.ImagePickerPlugin.a(Unknown Source:69)
	at io.flutter.plugins.imagepicker.ImagePickerPlugin.a(Unknown Source:27)
	at io.flutter.embedding.engine.c.a(Unknown Source:106)
	at c.a.b.a.e.a(Unknown Source:57)
	at c.a.b.a.d.onCreate(Unknown Source:22)
	at android.app.Activity.performCreate(Activity.java:7224)
	at android.app.Activity.performCreate(Activity.java:7213)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
	... 11 more

Minsdkversion 16
Targetsdkversion 28
Deviceos android pie

@dnfield dnfield added p: image_picker The Image Picker plugin. plugin c: crash Stack traces logged to the console platform-android Android applications specifically labels Jan 11, 2020
@dnfield
Copy link
Contributor

dnfield commented Jan 11, 2020

Does this reproduce for you in the image_picker example app? If not, can you provide a minimum reproduction so that this can be debugged/triaged?

@dnfield dnfield added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 11, 2020
@hb0nes
Copy link

hb0nes commented Jan 11, 2020

Confirmed. Works when devving, but when doing flutter build apk and running that, I get the same errors.

@hb0nes
Copy link

hb0nes commented Jan 12, 2020

I fixed this by disabling tree shaking with minifyEnabled and shrinkCode. It is simply bad and unreliable.

If anyone ever faces issues that pop up only during release build, try that.

@riyanWi
Copy link
Author

riyanWi commented Jan 13, 2020

Does this reproduce for you in the image_picker example app? If not, can you provide a minimum reproduction so that this can be debugged/triaged?

no, when I tried on example app it's work.
this is my code

  Future getImageCamera() async {
    var img = await ImagePicker.pickImage(
        source: ImageSource.camera, imageQuality: 60);
    setState(() {
      image = img;
    });
  }

  Future getImageGalery() async {
    var img = await ImagePicker.pickImage(
        source: ImageSource.gallery, imageQuality: 60);
    setState(() {
      image = img;
    });
  }

But when I remove that code and just import package image_picker my app still crash.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 13, 2020
@riyanWi
Copy link
Author

riyanWi commented Jan 13, 2020

I fixed this by disabling tree shaking with minifyEnabled and shrinkCode. It is simply bad and unreliable.

If anyone ever faces issues that pop up only during release build, try that.

it's fixed my problem. thank you very much

@BWhiteApps
Copy link

I fixed this by disabling tree shaking with minifyEnabled and shrinkCode. It is simply bad and unreliable.

If anyone ever faces issues that pop up only during release build, try that.

Can you give more details on how to do this?

@dnfield
Copy link
Contributor

dnfield commented Jan 13, 2020

I believe you can just pass --no-shrink to the Flutter tool to disable shrinking.

We shouldn't require you to disable shrinking for this plugin.
/cc @blasten - did we miss this one when evaluating proguard/r8 rules?

@dnfield dnfield added t: gradle "flutter build" and "flutter run" on Android t: shrink The "--shrink" feature of the Flutter tool labels Jan 13, 2020
@hb0nes
Copy link

hb0nes commented Jan 13, 2020 via email

@blasten
Copy link

blasten commented Jan 13, 2020

The issue is in the android_lifecycle plugin since it uses reflection: https://github.com/flutter/plugins/blob/master/packages/flutter_plugin_android_lifecycle/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java#L29-L30

That needs a proguard rule.

cc @amirh

@mklim
Copy link
Contributor

mklim commented Jan 13, 2020

Discussed with @amirh offline, the reflection was originally added in order to support 1.9 when it was stable. Now that a more recent version has rolled we should be able to avoid it entirely. I'll look into taking it out of flutter_plugin_android_lifecycle.

@mklim
Copy link
Contributor

mklim commented Jan 14, 2020

Version 1.0.4 of flutter_plugin_android_lifecycle has been published with the fix for this. This should be enough to resolve it for everyone on the latest Flutter stable, but people on older versions of Flutter will need to upgrade to the latest stable (v1.12) to get the fixed package version.

If you're still seeing this issue, please comment with minimal reproduction steps, your flutter version, and your pubspec.lock.

@seakingii
Copy link

Version 1.0.4 of flutter_plugin_android_lifecycle has been published with the fix for this. This should be enough to resolve it for everyone on the latest Flutter stable, but people on older versions of Flutter will need to upgrade to the latest stable (v1.12) to get the fixed package version.

If you're still seeing this issue, please comment with minimal reproduction steps, your flutter version, and your pubspec.lock.

Thant you!

I add " flutter_plugin_android_lifecycle: ^1.0.4" to pubspec.yaml
it's fixed my problem

@hb0nes
Copy link

hb0nes commented Jan 14, 2020

Version 1.0.4 of flutter_plugin_android_lifecycle has been published with the fix for this. This should be enough to resolve it for everyone on the latest Flutter stable, but people on older versions of Flutter will need to upgrade to the latest stable (v1.12) to get the fixed package version.

If you're still seeing this issue, please comment with minimal reproduction steps, your flutter version, and your pubspec.lock.

Very nice! We will attempt a build with tree shaking enabled soon, including your fix, on the latest stable at least. Will check with dev and beta channels as well.

@mayurdhurpate
Copy link

mayurdhurpate commented Jan 30, 2020

Would like to share (just for reference) that following was my experience related to this issue:

  • I recently did /android/ directory recreate using flutter create to switch from java to Kotlin, while preserving changes via git [I upgraded to 1.12 recently]. Also did some minor critical updates, checked on debug mode and (on an urgent deadline) pushed to production in night.
  • The app crashes in the morning in all the devices, including the new downloads as well as old ones updating. Confirmed by morning that there is an issue, and unluckily, I couldn't find this issue on Google search that time and felt it could be an issue with Git branches (as my VS Code was showing some weird errors.) I repaired the pub cache, did flutter clean, and close open VS code, and the app starts working. Just to be sure, I checked on dev(env) debug, prod(env) debug and prod release using flutter run. I thought I should test the appbundle once too, but thought it would unnecessary[crashes still hapenning].
  • Pushed another release at 13:00 which updates the app at 16:00, which again crashes [my co-founder is not happy]. :(
  • Then I decide to just revert back to the last working commit, defeating the whole purpose of a time-critical feature built for an event, and push the update. This update goes live at ~18:00 and works well.
  • Finally, at 23:00 I do a Google Search again (with a relaxed mind), and find this Github issue.

I am a solo developer in my team, and I'm able to build features fast, thanks to Flutter, and I have got huge respect for the small team at Google leading it. I'm sure they must be doing everything possible to reduce such cases.

Not sure what should I do to prevent such instances to happen in future? Have happened a few times before, due to other plugins, Android-specific/iOS-specific/Flutter core issue. Few things which come to my mind:

  • I think I should have pushed to Internal Test/Beta channel first to test it on Play Store.
  • I think I should have built an apk file too to test it to be installed via adb shell.
  • Should have researched well about the error when I received it the first time via Crashylytics.

Felt like sharing so that the team is aware of some case scenarios.

P.S. I received a prompt 1-2 times that an upgrade is available, but I chose to delay it owning tofact that it might take up some time fix any broken functionalities. Also, I couldn't find and release notes online for the latest version. Would be great if we add the link to them here: https://flutter.dev/docs/development/tools/sdk/releases?tab=macos

PiN73 added a commit to PiN73/plugins that referenced this issue Feb 6, 2020
This fixes crash if flutter_plugin_android_lifecycle: 1.0.3 is saved in pubspec.lock
flutter/flutter#48622
flutter/flutter#48906
PiN73 added a commit to PiN73/plugins that referenced this issue Feb 6, 2020
This fixes crash if flutter_plugin_android_lifecycle: 1.0.3 is saved in pubspec.lock
flutter/flutter#48622
flutter/flutter#48906
PiN73 added a commit to PiN73/plugins that referenced this issue Feb 6, 2020
This fixes crash if flutter_plugin_android_lifecycle: 1.0.3 is saved in pubspec.lock
flutter/flutter#48622
flutter/flutter#48906
PiN73 added a commit to PiN73/plugins that referenced this issue Feb 6, 2020
This fixes crash if flutter_plugin_android_lifecycle: 1.0.3 is saved in pubspec.lock
flutter/flutter#48622
flutter/flutter#48906
PiN73 added a commit to PiN73/plugins that referenced this issue Feb 6, 2020
This fixes crash if flutter_plugin_android_lifecycle: 1.0.3 is saved in pubspec.lock
flutter/flutter#48622
flutter/flutter#48906
@Bhuelsmann
Copy link

Bhuelsmann commented Oct 22, 2020

Hi, I ran into the same problem. I changed the Versions in my pubspec, but my App crashes again.

flutter_plugin_android_lifecycle: ^1.0.11
image_picker: ^0.6.7+12

10-22 12:14:24.269 22726-22726/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to destroy activity {de.facentis.pflanzmemo/io.flutter.embedding.android.FlutterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.d.c(androidx.lifecycle.f)' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4337)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4355)
at android.app.ActivityThread.access$1500(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.d.c(androidx.lifecycle.f)' on a null object reference
at io.flutter.plugins.imagepicker.ImagePickerPlugin.j()
at io.flutter.plugins.imagepicker.ImagePickerPlugin.f()
at io.flutter.embedding.engine.c.f()
at io.flutter.embedding.android.e.o()
at io.flutter.embedding.android.FlutterActivity.F()
at io.flutter.embedding.android.FlutterActivity.onDestroy()
at android.app.Activity.performDestroy(Activity.java:6608)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1154)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4315)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4355) 
at android.app.ActivityThread.access$1500(ActivityThread.java:181) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6145) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

Did I miss something else?

Edit: Maybe Fixed with Gradle Downgrade:3.6.3

@XDeepZeroX
Copy link

Привет, я столкнулся с той же проблемой. Я изменил версии в своем pubspec, но мое приложение снова вылетает.

flutter_plugin_android_lifecycle: ^ 1.0.11
image_picker: ^ 0.6.7 + 12

10-22 12: 14: 24.269 22726-22726 /? E / AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: невозможно уничтожить действие {de.facentis.pflanzmemo / io.flutter.embedding.android.FlutterActivity}: java.lang.NullPointerException: попытка вызвать виртуальный метод void androidx .lifecycle.dc (androidx.lifecycle.f) 'для ссылки
на нулевой объект в android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4337)
в android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:4355)
в android. app.ActivityThread.access $ 1500 (ActivityThread.java:181)
в android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1536)
в android.os.Handler.dispatchMessage (Handler.java:102)
на android.os. Looper.loop (Looper.java:145)
в android.app.ActivityThread.main (ActivityThread.java:6145)
в java.lang.reflect.Method.invoke (собственный метод)
в java.lang.reflect.Method.invoke (Method.java:372)
в com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399)
в com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194)
Вызвано: java.lang.NullPointerException: попытка вызвать виртуальный метод 'void androidx.lifecycle.dc (androidx.lifecycle.f)' в ссылке
на нулевой объект в io.flutter.plugins.imagepicker.ImagePickerPlugin.j ()
в io.flutter.plugins.imagepicker.ImagePickerPlugin.f ()
в io .flutter.embedding.engine.cf ()
в io.flutter.embedding.android.eo ()
в io.flutter.embedding.android.FlutterActivity.F ()
в io.flutter.embedding.android.FlutterActivity.onDestroy ()
в android.app.Activity.performDestroy (Activity.java:6608)
в android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1154)
в android.app.ActivityThread .performDestroyActivity (ActivityThread.java:4315)
в android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:4355) 
в android.app.ActivityThread.access $ 1500 (ActivityThread.java:181) 
в android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1536) 
в android.os.Handler.dispatchMessage (Handler.java:102) 
в android.os.Looper.loop (Looper.java:145) 
в android.app.ActivityThread.main (ActivityThread.java: 6145) 
в java.lang.reflect.Method.invoke (собственный метод) 
в java.lang.reflect.Method.invoke (Method.java:372) 
в com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) 
в com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194)

Я что-то еще пропустил?

Изменить: возможно, исправлено с помощью Gradle Downgrade: 3.6.3

flutter_plugin_android_lifecycle: ^1.0.11
image_picker: ^0.6.7+12

flutter build apk --no-shrink
it's fixed my problem.

@egodefroy
Copy link

Hi @TahaTesser
as per #48622 (comment) , tree shaking and minifyEnabled are not set in my gradle configuration. Does not seem to be relevant to my problem

@rj76
Copy link

rj76 commented Jan 25, 2021

For what it's worth, moving to flutter_plugin_android_lifecycle: ^1.0.4 also fixed an exception for me for file_picker.

@github-actions
Copy link

github-actions bot commented Aug 6, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: crash Stack traces logged to the console p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android t: shrink The "--shrink" feature of the Flutter tool waiting for PR to land (fixed) A fix is in flight
Projects
None yet
Development

Successfully merging a pull request may close this issue.