329

I am getting this error while I am building 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)

Tried to invalidate cache and restart android studio.Rebuild project but none of them works for me.

7
  • 1
    Yes. It is also showing heap size issue. But I have already allocated maximux heap size. Commented Aug 22, 2019 at 10:10
  • it is pretty much impossible to debug this with just his much info buddy, i thinki reddit/quora might be more helpful than stack, you wont be allowed to have discussions here Commented Aug 22, 2019 at 10:11
  • 6
    Thanks Kushan.I found a solution after adding "org.gradle.jvmargs=-Xmx4608m" in gradle.properties Commented Aug 22, 2019 at 10:16
  • here maybe help you. this is useful for me Commented Nov 3, 2020 at 9:39
  • 1
    This is just the start of the stack trace. You need to scroll down to where it says "Caused by:" and search on what follows. In my case it was a different cause and solution, which I finally found here: stackoverflow.com/a/47132142/989468 Commented Mar 1, 2021 at 23:55

60 Answers 60

577

This can be solved by increasing the amount of JVM memory available to Gradle.

Add (or edit) the following line in the gradle.properties file:

org.gradle.jvmargs=-Xmx4608m
Sign up to request clarification or add additional context in comments.

13 Comments

I have no idea what this does but it worked, can you add some info?
org.gradle.jvmargs represent the arguments that will be passed to the Java virtual machine used during build time. The Xmx option with a number (in this very special syntax) is commonly used to set the maximum size of the heap in megabytes, while Xms is used to set the minimal one.
for more guidance to this problem, scroll to the bottom of the stack trace, mine is Caused by: org.gradle.api.GradleException: Can't process attribute android:fillColor="@android:color/holo_red_dark": references to other resources are not supported by build-time PNG generation. File was preprocessed as vector drawable support was added in Android 5.0 (API level 21)
i have applied your solution but still getting error. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeDebugJavaResource'. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > File 'com.android.builder.files.ZipCentralDirectory@3a9a7373' was deleted, but previous version not found in cache
|
76

Try this, in Android Studio

File > Invalidate Caches/Restart... 

6 Comments

I did but I still got a similar error after building the project.
Also, try to clean the project and then File > Invalidate Caches/Restart... and check if that works
Yaday. Thanks for your reply. The problem was the latest unstable version of the Android Gradle build tool. I downgraded to the latest stable version and the problem's gone.
and you may sync gradle
I don't this is the right solution but it worked on me.
|
34

In my case, I enabled multidex

Open [project_folder]/app/build.gradle and add following lines.

defaultConfig {
    ...

    multiDexEnabled true
}

and

dependencies {
    ...

    implementation 'com.android.support:multidex:2.0.1'
}

1 Comment

Thanks, this helped. There's a new mutlidex version, implementation "androidx.multidex:multidex:$multidex_version". New update can be found here developer.android.com/build/multidex#about
32

I already had multidex enabled but the version was too old so upgraded and it fixed the issue:

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

3 Comments

implementation 'androidx.multidex:multidex:$multidex_version' with " ..." required not ' ...'
unfortunately I already have this version and still same problem
where should i put this code. please specify location
15

Encountered Similar issue... the fix for me was changing/updating the gradle version

   classpath "com.android.tools.build:gradle:4.1.2" 

to

   classpath "com.android.tools.build:gradle:4.1.3"

worked for me

1 Comment

I had a problem with classpath 'com.android.tools.build:gradle:7.2.0' but going back to classpath 'com.android.tools.build:gradle:7.1.3' resolved that
15

gradle.proprites

org.gradle.jvmargs=-Xmx1536M

build.gradle

defaultConfig {
        multiDexEnabled true
    }

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
}

and yet theses stuff did not fix my problem, until I increase the compileSdkVersion from 27 to 28, it worked for me.

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
         minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            crunchPngs false
        }
    }
}

1 Comment

crunchPngs false helped me
13

I removed this issue by adding the following lines

add multiDexEnabled true in android>app>build.gradle inside defaultConfig

add implementation 'com.android.support:multidex:1.0.3' in android>app>build.gradle inside dependencies

Comments

9

I got an stacktrace similar to yours only when building to Lollipop or Marshmallow, and the solution was to disable Advanved profiling.

Find it here:

Run -> Edit Configurations -> Profiling -> Enable advanced profiling

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

2 Comments

I accidentally enable advanced profiling and disabling it fixed the problem. Your answer helps me to get into that issue
This didn't work for me.
7

search your code you must be referring to color in color.xml in an xml drawable. go and give hex code instead of referencing....

Example: in drawable.xml you must have called

android:fillColor="@color/blue"

change it to android:fillColor="#ffaacc" hope it solve your problem...

1 Comment

THIS IS WORK FOR ME, THANK YOU.
7

classpath 'com.android.tools.build:gradle:3.3.2' Change the class path and it will work.

Comments

7

please check if current icons are not on debug folder if so move them to main folder or recreate them enter image description here

Comments

6

in my code i am using latest version of flutter and packages and remove this error by adding the line in

multiDexEnabled true 

in app level build.gradle

Comments

6

I also have the same issue , and you can add this

org.gradle.jvmargs=-Xmx4608m on your Gradle.properties

but in my case I change like this :

from : org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

to: org.gradle.jvmargs=-Xmx4608m -Dfile.encoding=UTF-8

Comments

5

In right side of android studio click gradle -> app -> build -> assemble. then android studio will start building, and print you a proper message of the issue.

Comments

5

Solution for:

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

All feature modules have to apply the library plugin and NOT the application plugin.

build.gradle (:androidApp:feature_A)

apply plugin: 'com.android.library'

It all depends on the stacktrace of each one. Cause 1 WorkExecutionException may be the consequence of other causes. So I suggest reading the full stacktrace from the last cause printed towards the first cause. So if we solve the last cause, it is very likely that we will have fixed the chain of causes from the last to the first.

I attach an example of my stacktrace where the original or concrete problem was in the last cause:

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

Feature Package ID was not set

Comments

5

This fixed my issue.

cd android && ./gradlew clean

Comments

5

just add

android.enableJetifier=true

to the gradle.properties .

actually this happens mostly when you mess up with androidx and support libraries, some dependencies are currently not fully supporting androidX. so you have to enable jetfier.

Comments

5

I solved this problem by adding this line to gradle.properties.

android.enableJetifier=true

Comments

4

Working on android studio: 3.6.3 and gradle version:

classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"

Adding this line in

gradle.properties file

org.gradle.jvmargs=-Xmx512m

Comments

3

found the solution.

add this code to your 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
    }


1 Comment

To be completely clear: after enabling multiDex, the error message will tell you exactly which file and line contains the error. Once fixed you can set multiDexEnabled back to false
3

I update this and worked for me in gradle wrapper properties

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

Comments

3

try to add this to your gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

Comments

2

If you've tried all the solutions above and still doesn't resolve your issue.

This might not seemed related, but here's my take on it.

Try removing this from your Gradle dependency, I've spend 2 hours of my time because of this roadblock.

implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"

Comments

2

I got this problem when I directly downloaded code files from GitHub but it was showing this error, but my colleague told me to use "Git bash here" and use the command to Gitclone it. After doing so it works fine.

Comments

2

In my case the issue was related to View Binding. It couldn't generate binding classes due to an invalid xml layout file. In the file I had a Switch with an id switch, which is a Java keyword. Renaming the Switch id resolved the issue.enter image description here

Comments

2

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

Comments

2

Make sure that:

Compile sdk version = build tools version = target sdk version

Comments

2

This is the snapshot of the issue that I was having.

Execution failed for task ':app:mergeDebugJavaResource'.

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 2 files found with path 'META-INF/gradle/incremental.annotation.processors' from inputs

This indicated that there were files causing a conflict during the merging process.

To resolve this issue I added this line of code on the packagingOptions.

android {
    ....

      packagingOptions {
        resources {
           excludes += '/META-INF/{AL2.0,LGPL2.1}'
            exclude 'META-INF/gradle/incremental.annotation.processors'
        }
    }
}

Comments

1

If any one having this issue in flutter after adding firebase storage. Do flutter clean and re run it, it will work

Comments

1

do invalidate caches and restart, later Restarting the laptop did the job for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.