我得到这个错误,而我正在构建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 Studio试试这个

File > Invalidate Caches/Restart... 

其他回答

解决方案:

Caused by 4: com.android.builder.internal.aapt.AaptException: Dependent features configured but no package ID was set.

所有特性模块都必须应用库插件,而不是应用程序插件。

构建。gradle (androidApp: feature_A)

apply plugin: 'com.android.library'

这完全取决于每个组件的堆栈跟踪。原因1 WorkExecutionException可能是其他原因导致的。因此,我建议从最后一个原因到第一个原因读取完整的堆栈跟踪。因此,如果我们解决了最后一个原因,很可能我们就已经固定了从最后一个原因到第一个原因的链条。

我附上我的堆栈跟踪的一个例子,原始或具体的问题是在最后的原因:

Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction

Caused by: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-4.2.0-alpha16-6840111-linux Daemon #0: Unexpected error during link, attempting to stop daemon.

Caused by: java.io.IOException: Unable to make AAPT link command.

Caused by 4: com.android.builder.internal.aapt.AaptException: Dependent features configured but no package ID was set.

GL

特性包ID未设置

类路径“com.android.tools.build: gradle: 3.3.2” 更改类路径就可以工作了。

改变后对我有用:

        <activity
        android:name="com.packagename.PurchaseActivity"
        android:configChanges="orientation|screenSize"
        android:label="@string/title_activity_purchase"
        android:screenOrientation="portrait" />

to

        <activity
        android:name=".PurchaseActivity"
        android:configChanges="orientation|screenSize"
        android:label="@string/title_activity_purchase"
        android:screenOrientation="portrait" />

删除包的名称,所有java类作为应用程序的一部分,它解决了我的问题:-)

该应用程序最近已迁移到AndroidX。

我已经启用了multidex,但版本太旧了,所以升级了,它修复了这个问题:

// Old version
implementation "com.android.support:multidex:1.0.3"
// New version
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"

找到了解决方案。

将此代码添加到build.gradle中,

dependencies {
    def multidex_version = "2.0.1"
    implementation 'androidx.multidex:multidex:$multidex_version'
}

then enable the multidex to true

 defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }