我得到这个错误,而我正在构建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工作室。重建项目,但没有一个为我工作。


当前回答

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

其他回答

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

删除文件夹名称上的空白路径它解决了问题

请检查当前图标是否不在调试文件夹中,如果是,请将它们移动到主文件夹或重新创建它们

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

org . gradle jvmargs = -Xmx4g。

当你试图构建一个使用VectorDrawable作为自适应图标的应用程序时,你可能会遇到这样的错误。和你的XML文件包含"android:fillColor"与<梯度>块:

res - drawable icon_with_gradient xml。

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="96dp"
    android:height="96dp"
    android:viewportHeight="100"
    android:viewportWidth="100">

    <path
        android:pathData="M1,1 H99 V99 H1Z"
        android:strokeColor="?android:attr/colorAccent"
        android:strokeWidth="2">
        <aapt:attr name="android:fillColor">
            <gradient
                android:endColor="#156a12"
                android:endX="50"
                android:endY="99"
                android:startColor="#1e9618"
                android:startX="50"
                android:startY="1"
                android:type="linear" />
        </aapt:attr>
    </path>
</vector>

渐变填充颜色通常用于自适应图标,例如在教程中这里,这里和这里。

即使布局预览工作正常,当你构建应用程序时,你会看到这样的错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Error while processing Project/app/src/main/res/drawable/icon_with_gradient.xml : null

(More info shown when the gradle build is run with --stack-trace flag):

Caused by: java.lang.NullPointerException
    at com.android.ide.common.vectordrawable.VdPath.addGradientIfExists(VdPath.java:614)
    at com.android.ide.common.vectordrawable.VdTree.parseTree(VdTree.java:149)
    at com.android.ide.common.vectordrawable.VdTree.parse(VdTree.java:129)
    at com.android.ide.common.vectordrawable.VdParser.parse(VdParser.java:39)
    at com.android.ide.common.vectordrawable.VdPreview.getPreviewFromVectorXml(VdPreview.java:197)
    at com.android.builder.png.VectorDrawableRenderer.generateFile(VectorDrawableRenderer.java:224)
    at com.android.build.gradle.tasks.MergeResources$MergeResourcesVectorDrawableRenderer.generateFile(MergeResources.java:413)
    at com.android.ide.common.resources.MergedResourceWriter$FileGenerationWorkAction.run(MergedResourceWriter.java:409)

解决方案是将文件icon_with_gradient.xml移动到drawable-v24/icon_with_gradient.xml或drawable-v26/icon_with_gradient.xml。这是因为梯度填充只在API 24 (Android 7)及以上版本中支持。VectorDrawable:无效的可绘制标签梯度