Android Gradle build error "AAPT2 aapt2-4.1.0-6503028-windows Daemon #0: Unexpected error during link, attempting to stop daemon."
Asked Answered
S

8

46

I got this error while trying to build an Android app:

Execution failed for task ':admin:processDebugResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
AAPT2 aapt2-4.1.0-6503028-windows Daemon #0: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.

Most other solutions I found were related to an image in the project being too large however, that didn't work for me as all my images had sizes below 50kb.

Surfactant answered 23/4, 2021 at 16:36 Comment(0)
S
78

I found that this error occurs when additional modules are created in the project and linked to other app modules (using implementation project) but the plugin in the module's build.gradle file is set to 'com.android.application' instead of 'com.android.library'.

I found this solution in an answer to a different issue here.

Surfactant answered 23/4, 2021 at 16:36 Comment(4)
I have submitted a bug report for this issuetracker.google.com/issues/188096932Aenea
Glad it helped!Surfactant
But that makes it a library not a module, right? From what I understand here: developer.android.com/studio/projects this makes a difference.Interested
According to that article, it's still a module, just now a library module. However, considering that you can't really use code from an Android app module in another app module without running into the above error, I think it's right for it to be a library module.Surfactant
C
43

I had a similar error when I tried upgrading the compileSdk and targetSdk versions to 34 (From 33).

What I had to do was to change my gradle plugin version from

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

to

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

I don't know what exactly is the issue here yet. But I got the idea from the Google's documentation. It does not specifically say to upgrade gradle plugin version but I sensed it from the section where they have mentioned about how to write compileSdk in AGP higher than 7.0.0 as compared to lower than 4.2.0.

I was so confused as to what happens to the AGP versions in between. But I thought of upgrading a AGP to higher than 7.0.0 and it worked fine.

If someone gets a better explanation of why this is the case, please comment. Thanks

Chlores answered 18/1 at 19:46 Comment(3)
4 years after, same problem, same solution, thanksBrusquerie
Had to upgrade from 7.0.0 to 7.1.2 and it worked. Thank you.Territory
Minimum should be 7.1.2, no matter what was previous version. Thank You.Thou
T
14

when upgrading the target SDK version to 34, I also set the compile SDK version to the same 34. Then I changed it as below.

    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 33
    targetSdkVersion = 34
Trussing answered 19/12, 2023 at 16:40 Comment(4)
This helped me to fix the issue, keeping compileSdkVersion = 33Boswall
Shouldn't the compileSdkVersion be equal to or greater than targetSdkVersion?Dewan
It shouldn't be equal or greater than. The target SDK version is mainly looking at the Android API level.Trussing
It's worked for me, thanks @Vidurajith DarshanaTitanate
K
5

The answer from user "Schnelldev" can be shortened: for the application, the plugin 'com.android.application' should be used, and for each individual module 'com.android.library'

Kist answered 22/4, 2023 at 17:27 Comment(0)
E
3

For me the issue was the compileSdkVersion. it was set as:
compileSdkVersion 34 (like my target version).

I fixed the issue by setting it to 33: compileSdkVersion 33

Excelsior answered 14/12, 2023 at 16:3 Comment(1)
This answer is less useful because compile version 33 is no longer acceptable.Sanmiguel
B
2

I faced the same issue while updating my app, The only change required in my case was

compileSdkVersion = 34

to

compileSdkVersion = 33

in app level build gradle.

Hope this will help you.

Brandnew answered 5/4 at 5:46 Comment(1)
This answer is less useful because compile version 33 is no longer acceptable.Sanmiguel
U
1

In Flutter 3.19, I updated the build script dependencies to the following:

dependencies {
    classpath 'com.android.tools.build:gradle:7.3.0'
}
Undercoat answered 25/3 at 20:11 Comment(0)
B
0

I had a similar problem because of gradle caches. Using https://github.com/rock3r/deep-clean helped

Bibbie answered 23/5 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.