Felix H
Felix H

Reputation: 189

Gradle build error of app after Android Studio 4.1 update

I have updated from Android Studio 4.0 to 4.1. After the update I cannot build my application anymore which worked fine before the update. When I build the project I am getting the following exception:

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':app:compressDebugAssets'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CompressAssetsWorkAction my\application\path\app\build\intermediates\merged_assets\debug\out

The folder my\application\path\app\build\intermediates\merged_assets\debug\out is empty.

What I tried to do:

My gradle configuration looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-R'
    buildToolsVersion "30.0.2"

    defaultConfig {
         applicationId "my.application.id"
         minSdkVersion 23
         targetSdkVersion 29
         versionCode 2
         versionName "1.1"
         multiDexEnabled true
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

         vectorDrawables {
             useSupportLibrary = true
         }
     }

     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
 }

 repositories {
     mavenCentral()
     maven { url 'https://maven.google.com' }
 }

 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation 'androidx.appcompat:appcompat:1.2.0'
     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
     implementation 'com.google.android.material:material:1.2.1'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
     implementation 'androidx.navigation:navigation-fragment:2.3.1'
     implementation 'androidx.navigation:navigation-ui:2.3.1'
     implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
     testImplementation 'junit:junit:4.13.1'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
     implementation "androidx.room:room-runtime:2.2.5"
     annotationProcessor "androidx.room:room-compiler:2.2.5"
     implementation 'com.github.bumptech.glide:glide:4.11.0'
     implementation 'androidx.multidex:multidex:2.0.1'
 }

Guys, I am out of ideas as I am no expert when it comes to gradle. Help would be most appreciated.

Upvotes: 2

Views: 6802

Answers (6)

Juan Rosero
Juan Rosero

Reputation: 11

I have this problem when I try to build apk with capacitor Ionic in Android Studio. My solution was:

First change the Android Gradle plugin in build.gradle to classpath 'com.android.tools.build:gradle:4.0.2' and in gradle-wrapper.properties change Gradle version to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip and press Sync Now.

When gradle sync is finish, close Android Studio Editor and go to project folder and inside android delete .idea and .gradle folders. Next you need to open PowerSheel in this location and run the code .\gradlew clean.

Finally, you can open the project with android studio using in vs npx cap open android or as you want, wait for sync gradle and then you can build your apk.

Upvotes: 0

Daniel Rourke
Daniel Rourke

Reputation: 1

Changing the location my projects from a FAT32 formatted drive to an NTFS drive solved the problem for me.

Upvotes: -2

Bamidele Clement Oke
Bamidele Clement Oke

Reputation: 96

I had a similar problem this morning after updating my Android studio. In my case, previous projects run well but if I create a new project and attempt to run, I will get the said error message. I changed the Android Gradle plugin version to 4.0.2 and the Gradle version to 6.1.1 from the project structure dialog and I was able to run the app successfully afterward.

Upvotes: 0

Jimi
Jimi

Reputation: 1

this solution may help. I had problems with this error showing up and I had no idea why. As it turns out, I save my android projects to a USB stick. The USB stick is formatted using PAL. I reformatted using NTFS and the problem has gone.

Upvotes: 0

Felix H
Felix H

Reputation: 189

I found a temporary solution in downgrading my Android Studio version to 4.0.2.
Additionally, I changed the Android gradle plugin version to 4.0.2 and the gradle version to 6.1.1 which I had installed before. You can do this under
File -> Project Structure -> Project.
Now I am able to run my application again. I am aware that this is only a temporary solution but at least I can work again on my application.
I will try to install Android Studio 4.2 Canary 15 the next days and check, if this works for me. I let you know.

Upvotes: 4

braop
braop

Reputation: 196

This is what usually works for me every time i make an update, I hope it works for you.

Sometimes gradle build fails because, downloading some dependencies required by gradle for a successful build are missing and need to be downloaded. So make sure your computer is online.

-> Click on gradle (right side of your android studio), then toggle the highlighted button in the pic below.

  1. Make sure its not highlighted, Cause if it is highlighted that means gradle is offline (has no access to internet)

  2. Then rebuild project to download the missing gradle dependencies.

enter image description here

I hope you find this useful.

Upvotes: 0

Related Questions