Search code examples
imageflutterpickerimagepicker

Flutter image_picker not working with flutter_plugin_android_lifecycle issue


I have followed all the steps to implement the image picker plugin in a fresh new app.

Added dependencies to pubspec.yaml

dependencies:
  image_picker: 0.6.2+3

Added to the menifest android:requestLegacyExternalStorage="true"

Followed the example code, But I am getting is this error..

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     ../project/android/app/src/main/AndroidManifest.xml:9:5-53:19: AAPT: error: attribute android:requestLegacyExternalStorage not found.

and

/Users/.../Documents/_sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.8/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:8: error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;
                         ^
/Users/.../Documents/_sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.8/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 1s

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

Whats the wrong am I doing here!


Solution

  • After an intensive search, i got the clue to solved this issue. The app need to compile against SDK 29, which is the latest buildTool includes the latest changes that were introduced in Android 10.

    Inside app level build.gradle file

    // ...
    android {
        compileSdkVersion 29
    // ....
            defaultConfig {
                targetSdkVersion 29
    //...
    

    I think this should be mentioned in the image_picker documentation.