Fail to run flutter with image_picker: ^0.6.7+9

Issue

I’ve got this error after adding image_picker: ^0.6.7+9 to my pubspec.yaml file and I’m already in AndroidX since my android/gradle.properties file has the androidX properties, as said in this documentation ‘https://flutter.dev/docs/development/androidx-migration’.

But I get this error anyway, and after searching and trying solutions for hours, I still unable to fix it.

Here is the error message.

C:\flutter.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.9\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:8: error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;
^
C:\flutter.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.9\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:22: error: cannot find symbol
public static Lifecycle getActivityLifecycle(
^
symbol: class Lifecycle
location: class FlutterLifecycleAdapter
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileReleaseJavaWithJavac’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 10s

Exception: The plugin flutter_plugin_android_lifecycle could not be built due to the issue above.

Solution

I just changed ‘compileSdkVersion’ and ‘targetSdkVersion’ to 29 and worked. (before was 28)
You can find these properties in ‘android/app/build.gradle’

Answered By – Márcio Valim

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *