image_picker and AndroidX compatibility issue

669 views
Skip to first unread message

and...@usego.se

unread,
Apr 3, 2019, 7:45:35 AM4/3/19
to Flutter Dev
Have anyone run into problems with image_picker and AndroidX?
I converted my flutter app to AndroidX according to the guidelines published on flutter.dev and now the app crashes with the stacktrace below as a result. I created a new app via flutter create, added the image_picker dependency and nothing else. Still the same result. It looks like FlutterActivity extends android.app.Activity
and not androidx.appcompat.app.AppCompatActivity, can that be the problem? How do I solve this? I have no issues when I run flutter doctor. 

2019-04-03 12:35:49.471 3822-3822/com.example.testandroidx E/AndroidRuntime: FATAL EXCEPTION: main
   
Process: com.example.testandroidx, PID: 3822
    java
.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testandroidx/com.example.testandroidx.MainActivity}: java.lang.ClassCastException: com.example.testandroidx.MainActivity cannot be cast to androidx.appcompat.app.AppCompatActivity
        at android
.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android
.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android
.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android
.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android
.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android
.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android
.os.Handler.dispatchMessage(Handler.java:106)
        at android
.os.Looper.loop(Looper.java:193)
        at android
.app.ActivityThread.main(ActivityThread.java:6669)
        at java
.lang.reflect.Method.invoke(Native Method)
        at com
.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com
.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     
Caused by: java.lang.ClassCastException: com.example.testandroidx.MainActivity cannot be cast to androidx.appcompat.app.AppCompatActivity
        at io
.flutter.plugins.imagepicker.ImagePickerPlugin.registerWith(ImagePickerPlugin.java:39)
        at io
.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:14)
        at com
.example.testandroidx.MainActivity.onCreate(MainActivity.kt:11)
        at android
.app.Activity.performCreate(Activity.java:7136)
        at android
.app.Activity.performCreate(Activity.java:7127)
        at android
.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android
.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android
.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android
.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android
.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android
.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android
.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android
.os.Handler.dispatchMessage(Handler.java:106)
        at android
.os.Looper.loop(Looper.java:193)
        at android
.app.ActivityThread.main(ActivityThread.java:6669)
        at java
.lang.reflect.Method.invoke(Native Method)
        at com
.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com
.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.3.8, on Mac OS X 10.14.2 18C54, locale en-SE)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[✓] IntelliJ IDEA Community Edition (version 2019.1)
[✓] VS Code (version 1.30.1)
[✓] Connected device (2 available)

• No issues found!

Mayur Prajapati

unread,
Apr 3, 2019, 8:08:00 AM4/3/19
to Flutter Dev
Try opening android folder in Android Studio and after gradle build finished press double shift search for androidx and there is option to migrate to AndroidX.
Migrate from there. It didn't gave me any error and yeah, latest version of image_picker already supports AndroidX.

If you are using older version of image_picker then you have to change android source code of image_picker located in android/~image_picker(open android folder in Android Studio).
Replace imports of support package to androidx package.
And also change package name of FileProvider in image_picker/AndroidManifest.xml..

Hope this will help you :)

John Osborn

unread,
Apr 3, 2019, 8:08:49 AM4/3/19
to and...@usego.se, Flutter Dev

The only problem I have had was related to permissions. I had to ask for permission to access storage and camera, even though the docs say you should not have to.

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

and...@usego.se

unread,
Apr 3, 2019, 9:07:35 AM4/3/19
to Flutter Dev
Thanks for your suggestions! I got it working now, I am not sure what it was that did the trick. 
This is what I did, maybe it will help someone else.

I removed image_picker from pubspec.yaml and clicked on get packages. Deleted the plugin from ```~/.pub-cache/hosted/pub.dartlang.org/```. Re-added the plugin again and now it works, hopefully forever. :) Maybe there was something added by mistake during the conversion to AndroidX. 

Thanks!

Vea Sna

unread,
Apr 3, 2019, 10:21:01 AM4/3/19
to and...@usego.se, Flutter Dev


នៅ 3 មេសា 2019 8:07 ល្ងាច, <and...@usego.se> បាន​សរសេរ៖

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages