我得到这个错误,而我正在构建APK。

Cause 1: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkerExecution.waitForCompletion(DefaultWorkerExecutor.java:285)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:115)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:87)
    at org.gradle.workers.internal.DefaultWorkerExecutor.await(DefaultWorkerExecutor.java:150)
    at com.android.build.gradle.internal.tasks.Workers$WorkerExecutorAdapter.await(Workers.kt:282)
    at com.android.ide.common.resources.MergeWriter.end(MergeWriter.java:48)
    at com.android.ide.common.resources.MergedResourceWriter.end(MergedResourceWriter.java:242)
    at com.android.ide.common.resources.DataMerger.mergeData(DataMerger.java:292)
    at com.android.ide.common.resources.ResourceMerger.mergeData(ResourceMerger.java:384)
    at com.android.build.gradle.tasks.MergeResources.lambda$doFullTaskAction$1(MergeResources.java:261)
    at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:58)

试图使缓存无效并重新启动android工作室。重建项目,但没有一个为我工作。


当前回答

在android文件夹根的本地属性中设置最小sdk版本为21:

flutter.minSdkVersion=21

在app->build.gradle中

defaultConfig {
        [...]
        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()

根据文件:

注意:当针对Android SDK 21或更高版本时,Multidex支持是原生的。

他们还谨慎地警告说:

但是,不建议仅仅针对API 21+来解决多重索引问题,因为这可能会无意中排除运行旧设备的用户。

但是SDK 21在10年前就发布了Android版本5,0 Lollipop,如你所见:https://en.wikipedia.org/wiki/Android_Lollipop(更不用说这些设备,如果它们仍然存在,通常有能力升级他们的Android版本)。

其他回答

在android工作室的右侧 点击gradle -> app -> build -> assemble。 然后android工作室将开始构建,并打印您的问题的正确消息。

最后通过将这一行添加到gradle.properties找到了解决方案。

org.gradle.jvmargs = -Xmx4608m

How To Solve A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Error? To Solve A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Error Just open your app/build.gradle file and change this line. androidx.core:core-ktx:+ replace with androidx.core:core-ktx:1.6.0 Here is an Example. If you are using androidx.core:core-ktx:+ then this will find the latest version of androidx.core:core-ktx:+ and the latest one is 1.7.0 and the latest version needs the Android 31 compile SDK. So that You are facing this issue. Here is Two Possible Solution use a specific version, use androidx.core:core-ktx:${version} instead of androidx.core:core-ktx:+ upgrade the compile SDK to Android 31 full article is Here

我只有在构建棒棒糖或棉花糖时,才得到与您类似的堆栈跟踪,解决方案是禁用高级剖析。

在这里找到它:

执行命令-> Edit Configurations -> Profiling ->启用高级剖析

https://stackoverflow.com/a/58029739/860488

这里我发现只需添加这一行gradle.properties

org . gradle jvmargs = -Xmx4g。