【问题标题】:Flutter image_picker not working with flutter_plugin_android_lifecycle issueFlutter image_picker 不适用于 flutter_plugin_android_lifecycle 问题
【发布时间】:2020-07-26 20:41:08
【问题描述】:

我已按照所有步骤在全新应用中实现图像选择器插件。

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

我在这里做错了什么!

【问题讨论】:

  • 确保此文件“project/android/app/src/main/AndroidManifest.xml”中存在这一行“android:requestLegacyExternalStorage="true"”
  • 我已经添加了行

标签: image flutter picker imagepicker


【解决方案1】:

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

应用层内build.gradle文件

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-06
    • 2021-05-05
    • 2020-08-13
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    相关资源
    最近更新 更多