'Flutter - Unable to Install Application to Emulator

I have a Flutter project that previously run on Flutter 2.2. Recently, I upgraded to Flutter 2.10 but unable to run the application on Android emulator. I've followed the instruction on https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects. I run the emulator on Ubuntu.

What I've tried (from other StackOverflow posts) didn't work at all:

  • Restarting emulator
  • Removing dependencies (I removed all dependencies in pubspec.yaml)
  • Accepting Android SDK licenses
  • Using Android Pie version emulator
  • Running flutter clean
  • Uninstall the app on the emulator

flutter doctor shows no problem. Sometimes the run process stuck on Installing/built APK, sometimes I get 'Error connecting to the service protocol'. I also get the following error

✓  Built build/app/outputs/flutter-apk/app-debug.apk.
E/AndroidRuntime(10386): FATAL EXCEPTION: main
E/AndroidRuntime(10386): Process: com.app.example, PID: 10386
E/AndroidRuntime(10386): java.lang.NoSuchMethodError: No static method getMainExecutor(Landroid/content/Context;)Ljava/util/concurrent/Executor; in class Landroidx/core/content/ContextCompat; or its super classes (declaration of 'androidx.core.content.ContextCompat' appears in /data/app/com.app.example-pnJtFUSDIe4xWUHIPO1jNQ==/base.apk)
E/AndroidRuntime(10386):    at io.flutter.embedding.android.FlutterView.onAttachedToWindow(FlutterView.java:483)
E/AndroidRuntime(10386):    at android.view.View.dispatchAttachedToWindow(View.java:18347)
E/AndroidRuntime(10386):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
E/AndroidRuntime(10386):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
E/AndroidRuntime(10386):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
E/AndroidRuntime(10386):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
E/AndroidRuntime(10386):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
E/AndroidRuntime(10386):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
E/AndroidRuntime(10386):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
E/AndroidRuntime(10386):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
E/AndroidRuntime(10386):    at android.view.Choreographer.doCallbacks(Choreographer.java:761)
E/AndroidRuntime(10386):    at android.view.Choreographer.doFrame(Choreographer.java:696)
E/AndroidRuntime(10386):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
E/AndroidRuntime(10386):    at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime(10386):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10386):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(10386):    at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime(10386):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10386):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(10386):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I can run the same code (on the same project) to web browser. I can run the same code on the emulator if it's copied to another newly created project which is created with Flutter 2.10. I also have copied AndroidManifest.xml, build.gradle from the new project to the old one, but also not working.

Any solution or suggestion what should I do to fix it.



Solution 1:[1]

It looks like you still have references to previous versions of android libraries com.android... , latest flutter uses androidX.

Make sure you don't have any of

implementation 'com.android....`

in your gradle files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Iliya Gug