首页 > 解决方案 > Flutter image_picker 不适用于flutter_plugin_android_lifecycle 问题

问题描述

我已经按照所有步骤在一个全新的应用程序中实现了图像选择器插件。

向 pubspec.yaml 添加了依赖项

dependencies:
  image_picker: 0.6.2+3

添加到清单中 android:requestLegacyExternalStorage="true"

遵循示例代码,但我得到的是这个错误..

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.

/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.

我在这里做错了什么!

标签: imageflutterpickerimagepicker

解决方案


经过深入搜索,我得到了解决这个问题的线索。该应用程序需要针对 SDK 29 进行编译,这是最新的 buildTool,包括 Android 10 中引入的最新更改。

内部应用程序级别build.gradle文件

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

我认为这应该在image_picker文档中提及。


推荐阅读