33

I can't run my app on AVD. I get this error.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

My build.gradle

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 15
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}[E][1]}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}

enter image description here

Boken
  • 4,825
  • 10
  • 32
  • 42
  • https://stackoverflow.com/questions/57606462/a-failure-occurred-while-executing-com-android-build-gradle-internal-tasks – Sana Ebadi Sep 24 '19 at 16:49
  • @sanaebadi I fixed 'org.gradle.jvmargs=-Xmx4608m' in gradle.properties but it's can't work. Still error at same. :( – Worramet Chairungruang Sep 25 '19 at 11:02
  • send build.gradle for project and gradle-wrapper – Sana Ebadi Sep 25 '19 at 11:51
  • @sanaebadi My build.gradle for project and gradle-wrapper are on my comment. – Worramet Chairungruang Sep 25 '19 at 14:02
  • Does this answer your question? [A failure occurred while executing com.android.build.gradle.internal.tasks](https://stackoverflow.com/questions/57606462/a-failure-occurred-while-executing-com-android-build-gradle-internal-tasks) – VahidHoseini Jan 14 '21 at 21:12
  • Recommend updating your gradle and gradle plugin as well as your compileSdkVersion (current is 31) and then bump build tools version to match that (should be 30.0.3 to match compileSdk 31). If you get a "corrupted build tools" error asking you to reinstall the tools ( i did when I first upgraded our project) please see the solution to the below question to fix the issue, you will need to change some file types under the Gralde files https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted – Nicolas Mage Feb 03 '22 at 21:45

22 Answers22

34

Finally I fixed it.

  • Change org.gradle.jvmargs=-Xmx1536m to org.gradle.jvmargs=-Xmx1536m -Duser.country=US -Duser.language=en

  • Change classpath 'com.android.tools.build:gradle:3.5.0' to classpath 'com.android.tools.build:gradle:3.4.2'


Android Studio - How to fix Internal error when trying to read zip file

Boken
  • 4,825
  • 10
  • 32
  • 42
  • 4
    Thank you man, `org.gradle.jvmargs=-Xmx1536m -Duser.country=US -Duser.language=en` worked for me – LeoSantana Apr 16 '20 at 21:47
  • 1
    I change for my part `classpath 'com.android.tools.build:gradle:3.5.3'` to `classpath 'com.android.tools.build:gradle:3.5.2'` – gigeos Oct 03 '20 at 17:45
11

Simply degrade the version from

classpath 'com.android.tools.build:gradle:3.5.0'

to

classpath 'com.android.tools.build:gradle:3.4.2'

then no need to change anything,

You can try Invalidate Caches/Restart if not working.

Boken
  • 4,825
  • 10
  • 32
  • 42
Sumit Singh
  • 1,150
  • 13
  • 17
  • 2
    Had to downgrade from Gradle version 4.0.0 to 3.4.2 while building with Ionic. Do you by any chance know why this solution works? – EnigmaTech Oct 04 '20 at 18:48
  • 2
    Downgrading from 4.0.1 to 3.4.2 was the only solution that worked for me. Thanks! – YEG Oct 08 '20 at 21:45
3

This worked:

gradle.properties.org.gradle.jvmargs=-xmx4608m
Boken
  • 4,825
  • 10
  • 32
  • 42
silexcorp
  • 1,151
  • 1
  • 12
  • 13
  • 1
    Earlier, invalidate cache and restart worked for me but the problem surfaced again. Then gradle.properties.org.gradle.jvmargs=-xmx4608m worked. – Sam Reyes Jul 13 '20 at 16:38
2

Make sure you have enough RAM for gradle process by updating org.gradle.jvmargs in your gradle.properties.

Make sure your Gradle version and gradle plugin are compatible; refer to this table: https://developer.android.com/studio/releases/gradle-plugin#updating-gradle (i suggest plugin 3.5.3 with gradle 5.4.1 as of this writing!)

And what might be happening to some without knowing it, is not using JDK 8! I tried with JDK 11 and saw many different R8 and dexing errors! Also looks like this whole setup does not work with Eclipse OpenJ9 JDK distribution! so make sure you are using standard OpenJDK of your OS (mine would be default OpenJDK-8 from Debian)

kevoroid
  • 5,052
  • 5
  • 34
  • 43
  • I modified my `gradle.properties` file with the following line to solve OutOfMemroyError exception while running an Android build. My understanding is that this is double the default memory settings, and that increasing the Xmx value will give better results vs the XX:MaxPermSize parameter. If you need more, just increase the Xmx parameter. `org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m` – Tyler Forsythe Sep 24 '21 at 19:59
2

I had the same issue in my flutter project and it happened suddenly when trying to build/debug. Nothing worked not even "File > Invalidate Caches/Restart..." Finally I did a "flutter clean" and "flutter packages get" and it worked.

PearlByte
  • 59
  • 3
2

Run Flutter Clean, then restart your machine.

That did it for me.

Robert
  • 21
  • 1
2

For those who are scared of degrading gradle or so, recommend doing it because that resolved the issue for me. Dowgraded from:

classpath 'com.android.tools.build:gradle:4.0.3'

to:

classpath 'com.android.tools.build:gradle:4.0.0'
SenyaOhar
  • 81
  • 1
  • 8
1

This error can also be arise due any vector asset. I resolve by removing that vector asset file. Please check if you recently made any change to your vector asset file.

pankaj
  • 29
  • 1
1

I'm using Android Studio 4.0.0 and everything is fine until suddenly I got this error when clean and rebuild project. I don't know why. I tried many solution suggested but no luck. Finally I try to uninstall Android Studio 4.0.1 and this error is GONE and enable to run in emulator like before

Dharman
  • 30,962
  • 25
  • 85
  • 135
1

Had same issue, proposed solutions did't work for me. In my case problem was caused by signing config: I did set storePassword field, but didn't set keyPassword field in my signingConfigs section (passwords were same). So if you have your signing config in app's build.gradle file, try to set Key Password field in File -> Project Structure -> Modules dialogue or by adding keyPassword field in your signingConfigs section in build.gradle:

android {
    signingConfigs {
        release {
            storeFile file('C:\\PathToKey\\key.jks')
            storePassword 'myPassword'
            keyAlias 'myAlias'
            keyPassword 'myPassword'
        }
    }
    ...
}
the korovay
  • 563
  • 4
  • 16
  • 1
    For some reason, the way I had it set up to pull the keyPassword from a file stopped working. I'd have NEVER thought to investigate that based on this extremely weird error, thanks so much! – kodi Nov 03 '21 at 20:50
1

It worked.Use these commands on VSCode.

  1. flutter clean
  2. flutter pub cache repair
nafees ahmed
  • 948
  • 1
  • 12
  • 18
1

In my case problem arose due to gradle version upgradation from 6.2 all to 6.6 all in gradle wrapper. So i wiped 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

1

Adding this line to gradle.properties.

org.gradle.jvmargs=-Xmx4608m
Kingsley Mitchell
  • 2,412
  • 2
  • 18
  • 25
1

I got the same error. This solved mine.

  1. Change 'com.android.tools.build:gradle:3.5.0' to 'com.android.tools.build:gradle:4.1.3'
  2. File -->> Invalid caches/Restart
  3. pubspec.yaml -->> pub upgrade
  4. Change dependencies version to latest
  5. Pub get
  6. flutter run
GeekyChick
  • 17
  • 4
0

Check if your APK is locked by external tool (or even IDE)

(...)\app\release\app-release.apk
Grzesl
  • 41
  • 5
0

In my case i was mentioned android:src = "@drawable/screen" in launch_background.xml file.

but, could not added image in drawable folder. Putting image screen.jpg in drawable folder fixed my issue.

enter image description here

Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
0

I had the same issue and I upgrade the compiled SDK version and IT worked fine.

Liza
  • 23
  • 8
0

For FLutter, make sure you added android/key.properties

storeFile=/Users/umerwaqas/Downloads/keystore/THREADS AI.jks
storePassword=123456
keyAlias=userapp
keyPassword=123456

enter image description here

-1

In my case I solved the problem

  1. uninstalling my antivirus which was fishy (downloaded from chrome).

"ionic cordova build android" command started working again

Avkro
  • 1
-2

well the thing i do was simply restarting my computer. It works for a lot of these kind of rubbish errors android studio raises.

-2

player - publishing setting- build under - custom main manifest deselect build again

emrettc
  • 1
  • 1
-3

My build.gradle (Project)

buildscript {
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}
allprojects {
repositories {
    google()
    jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

My gradle-wrapper

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip