[android] A failure occurred while executing com.android.build.gradle.internal.tasks

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.

This question is related to android android-studio gradle

The answer is


Finally found a solution for this by adding this line to gradle.properties.

org.gradle.jvmargs=-Xmx4608m


Try this, in Android Studio

File > Invalidate Caches/Restart... 

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'

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


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


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...


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


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.


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

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


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


In my case problem arose due to gradle version upgradation from 6.2 all to 6.6 all in gradle wrapper. So i wiped out data of avd and restarted it and then deleted .gradle folder in android/.gradle and then run yarn start --reset-cache and yarn android. Then it worked for me


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.


If you getting this error saying signing-config.json (Access denied) means just exit the android studio and just go to the desktop home and click on the android studio icon and give Run as Administrator, this will sort out the problem (or) you can delete the signing-config.json and re-run the program :)


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


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
    }



Clean Project -> Invalidate caches/restart. My problem resolved with this.


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"


I was also facing the same problem a few minutes before when I tried to run a flutter project in my C/(.something../.something../.something../.something....) directory,

So I created a new folder in my E directory and started a new project there and when I run it ..... surprisingly it worked. I don't know why?

This was the message that I got after running in E: directory

Launching lib\main.dart on Lenovo K33a42 in debug mode...
Running Gradle task 'assembleDebug'...
Checking the license for package Android SDK Platform 28 in 
C:\Users\Shankar\AppData\Local\Android\sdk\licenses
License for package Android SDK Platform 28 accepted.
Preparing "Install Android SDK Platform 28 (revision: 6)".
"Install Android SDK Platform 28 (revision: 6)" ready.
Installing Android SDK Platform 28 in 
C:\Users\Shankar\AppData\Local\Android\sdk\platforms\android-28
"Install Android SDK Platform 28 (revision: 6)" complete.
"Install Android SDK Platform 28 (revision: 6)" finished.
Parameter format not correct -
v Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
Debug service listening on ws://127.0.0.1:51105/5xCsT5vV62M=/ws
Syncing files to device Lenovo K33a42...

You may get an error like this when trying to build an app that uses a VectorDrawable for an Adaptive Icon. And your XML file contains "android:fillColor" with a <gradient> block:

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>

Gradient fill colors are commonly used in Adaptive Icons, such as in the tutorials here, here and here.

Even though the layout preview works fine, when you build the app, you will see an error like this:

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)

The solution is to move the file icon_with_gradient.xml to drawable-v24/icon_with_gradient.xml or drawable-v26/icon_with_gradient.xml. It's because gradient fills are only supported in API 24 (Android 7) and above. More info here: VectorDrawable: Invalid drawable tag gradient


I know this might not be a complete or exact solution, but for those who are still facing issues even after doing what is given on this thread, check for your files in value folder. For me there was a typo and some missing values. Once i fixed them this error stopped.


Questions with android tag:

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8? "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator WebView showing ERR_CLEARTEXT_NOT_PERMITTED although site is HTTPS WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' GoogleMaps API KEY for testing Can I use library that used android support with Androidx projects. How to allow all Network connection types HTTP and HTTPS in Android (9) Pie? Android Material and appcompat Manifest merger failed Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 How to format DateTime in Flutter , How to get current time in flutter? How to change package name in flutter? Failed to resolve: com.android.support:appcompat-v7:28.0 What is AndroidX? Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve FirebaseInstanceIdService is deprecated installation app blocked by play protect Handling back button in Android Navigation Component Android design support library for API 28 (P) not working Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Install Android App Bundle on device Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. How to develop Android app completely using python? Invoke-customs are only supported starting with android 0 --min-api 26 Flutter.io Android License Status Unknown How to open Android Device Monitor in latest Android Studio 3.1 Default interface methods are only supported starting with Android N How can I change the app display name build with Flutter? Error:(9, 5) error: resource android:attr/dialogCornerRadius not found error: resource android:attr/fontVariationSettings not found Flutter does not find android sdk Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0) Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior flutter run: No connected devices Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation' PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT (in windows 10)

Questions with android-studio tag:

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK Invoke-customs are only supported starting with android 0 --min-api 26 How do I convert 2018-04-10T04:00:00.000Z string to DateTime? How to open Android Device Monitor in latest Android Studio 3.1 flutter run: No connected devices Dart SDK is not configured PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT (in windows 10) Execution failed for task ':app:compileDebugJavaWithJavac' Android Studio 3.1 Update Android Studio AVD - Emulator: Process finished with exit code 1 Android Studio Emulator and "Process finished with exit code 0" How can I fix "Design editor is unavailable until a successful build" error? INSTALL_FAILED_USER_RESTRICTED : android studio using redmi 4 device Why AVD Manager options are not showing in Android Studio Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error) "The specified Android SDK Build Tools version (26.0.0) is ignored..." Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0 Getting error "The package appears to be corrupt" while installing apk file Android studio 3.0: Unable to resolve dependency for :app@dexOptions/compileClasspath': Could not resolve project :animators Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0] Android Studio 3.0 Flavor Dimension Issue Android Studio - Failed to notify project evaluation listener error Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 Application Installation Failed in Android Studio Error:Failed to open zip file. Gradle's dependency cache may be corrupt Difference between signature versions - V1 (Jar Signature) and V2 (Full APK Signature) while generating a signed APK in Android Studio? Error:Cause: unable to find valid certification path to requested target How to switch from the default ConstraintLayout to RelativeLayout in Android Studio Installation failed with message Invalid File Warnings Your Apk Is Using Permissions That Require A Privacy Policy: (android.permission.READ_PHONE_STATE) error: package com.android.annotations does not exist 'Source code does not match the bytecode' when debugging on a device How to completely uninstall Android Studio from windows(v10)? How to show DatePickerDialog on Button click? You have not accepted the license agreements of the following SDK components Enable VT-x in your BIOS security settings (refer to documentation for your computer) "unable to locate adb" using Android Studio DELETE_FAILED_INTERNAL_ERROR Error while Installing APK Gradle Sync failed could not find constraint-layout:1.0.0-alpha2 This view is not constrained vertically. At runtime it will jump to the left unless you add a vertical constraint Android Studio Error: Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you're running

Questions with gradle tag:

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0) Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation' Execution failed for task ':app:compileDebugJavaWithJavac' Android Studio 3.1 Update Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex in Android Studio 3.0 "The specified Android SDK Build Tools version (26.0.0) is ignored..." Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle Failed to resolve: com.android.support:appcompat-v7:26.0.0 Setting up Gradle for api 26 (Android) What's the difference between implementation and compile in Gradle? More than one file was found with OS independent path 'META-INF/LICENSE' Android Studio 3.0 Flavor Dimension Issue Jersey stopped working with InjectionManagerFactory not found Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci Gradle - Could not target platform: 'Java SE 8' using tool chain: 'JDK 7 (1.7)' Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details Error:Failed to open zip file. Gradle's dependency cache may be corrupt Error:Cause: unable to find valid certification path to requested target gradlew command not found? error: package com.android.annotations does not exist You have not accepted the license agreements of the following SDK components How do I activate a Spring Boot profile when running from IntelliJ? Difference between using gradlew and gradle Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Automatically accept all SDK licences Gradle Sync failed could not find constraint-layout:1.0.0-alpha2 Error:Conflict with dependency 'com.google.code.findbugs:jsr305' How to run bootRun with spring profile via gradle task The number of method references in a .dex file cannot exceed 64k API 17 How to set an environment variable from a Gradle build? Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease' No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes configuring project ':app' failed to find Build Tools revision "Gradle Version 2.10 is required." Error Gradle version 2.2 is required. Current version is 2.10 Difference between clean, gradlew clean How to downgrade to older version of Gradle Error:Unknown host services.gradle.org. You may need to adjust the proxy settings in Gradle Gradle Error:Execution failed for task ':app:processDebugGoogleServices' failed to find target with hash string android-23