image_picker 在构建中抛出的异常

One*_*ent 8 flutter flutter-dependencies

我现在两天都在与 image_picker 搏斗。当我试图调试我的应用程序时,它从昨天中午开始。之前它会调试得很好,据我所知,在那段时间我没有改变任何东西。它unexpected element <queries> found in <manifest>.抛出错误,就像今天下面的错误日志一样,它启动了Jetfier来解决不兼容问题。Jetfier 昨天抛出的错误类似于SDK location not found. Define location in local.properties or with an ANDROID_SDK_ROOT environment variable. 但是 SDK 位置是在 local.properties 中定义的,我还创建了ANDROID_SDK_ROOTenv。SDK 位置的变量,但错误保持不变。

今天我彻底清除了flutter文件夹并重新安装了它。在那之后,我在设备信息方面遇到了一些问题,但最终得到了解决。现在我被困在这里,我没有任何进展。如果我删除<queries>in AndroidManifest.xml,它会在尝试运行程序时再次放在那里,所以这不是解决方案。

我把它pubspec.yaml作为file_picker: ^2.0.10下依赖和我试过pub getpub cache repairpub clean在不同的订单。如果我删除项目中的file_picker和所有它的用途,应用程序的其余部分运行得很好。我file_picker在另一个项目中尝试了一些更基本的东西,它也在那里抛出了同样的异常。

下面是错误代码。如果您需要更多详细信息,请告诉我。

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
     C:\Users\ASUS\AndroidStudioProjects\flutterdb\intern1\build\file_picker\intermediates\library_manifest\debug\AndroidManifest.xml:9:5-15:15: AAPT: error: unexpected element <queries> found in <manifest>.


* 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

BU?LD FAILED in 21s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin file_picker...
Running Gradle task 'assembleAarRelease'...

C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:10: error: cannot find symbol
import androidx.lifecycle.DefaultLifecycleObserver;
                         ^
  symbol:   class DefaultLifecycleObserver
  location: package androidx.lifecycle
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:20: error: cannot find symbol
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
                                                    ^
  symbol:   class FlutterLifecycleAdapter
  location: package io.flutter.embedding.engine.plugins.lifecycle
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:38: error: cannot find symbol
            implements Application.ActivityLifecycleCallbacks, DefaultLifecycleObserver {
                                                               ^
  symbol:   class DefaultLifecycleObserver
  location: class FilePickerPlugin
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:45: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:49: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:53: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:57: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:61: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:66: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:277: error: cannot find symbol
            this.lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
                             ^
  symbol:   variable FlutterLifecycleAdapter
  location: class FilePickerPlugin
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:278: error: incompatible types: FilePickerPlugin.LifeCycleObserver cannot be converted to LifecycleObserver
            this.lifecycle.addObserver(this.observer);
                                           ^
C:\Users\ASUS\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\file_picker-2.0.10\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:286: error: incompatible types: FilePickerPlugin.LifeCycleObserver cannot be converted to LifecycleObserver
        this.lifecycle.removeObserver(this.observer);
                                          ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
12 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

BU?LD FAILED in 3s

Exception: The plugin file_picker could not be built due to the issue above.
Run Code Online (Sandbox Code Playgroud)

sul*_*rza 17

对于那些不知道的人(包括我自己)有两个build.gradle文件

  1. android/build.gradle
  2. android/app/build.gradle

步骤 1 里面 android/build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        // classpath 'com.android.tools.build:gradle:3.5.0' before
        classpath 'com.android.tools.build:gradle:4.0.1' // after
    }
}
Run Code Online (Sandbox Code Playgroud)

里面的第2步 android/gradle/wrapper/gradle-wrapper.properties


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

# BEFORE
# distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
# AFTER
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

Run Code Online (Sandbox Code Playgroud)

第 3 步重建项目

可能需要一段时间,因为它会下载新的 gradle


Sha*_*man 12

这是因为在 Android 11 及更高版本 (SDK 30+) 中引入了新的包可见性选项。因此,您需要使用包含此更改的版本更新 build.gradle。以下是支持的 gradle 选项列表。

'3.3.3'、'3.4.3'、'3.5.4'、'3.6.4'、'4.0.1'

不要忘记更新 gradle-wrapper.properties 中的 ditributionUrl。例如,对于 gradle 4.0.1,你应该有:

distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

参考: https : //github.com/miguelpruivo/flutter_file_picker/wiki/Troubleshooting#android


Jah*_*tul 7

** 最新更新 **

android/build.gradle 中的步骤 1

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
    google()
    jcenter()
}

dependencies {
    // change to build:gradle:3.6.3
    classpath 'com.android.tools.build:gradle:3.6.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.3'
}
Run Code Online (Sandbox Code Playgroud)

}

android/gradle/wrapper/gradle-wrapper.properties 中的步骤 2

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
// change distributionUrl to gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Run Code Online (Sandbox Code Playgroud)