Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Asked Answered
B

49

139

This is the output of my Gradle console, I am unable to build my project

D:\Android Projects\....\app\src\main\res\layout\topic_view_header.xml
Error:error: resource attr/?? (aka -packagename- :attr/??) not found.
Error:error: resource attr/?? (aka -packagename-:attr/??) not found.
Error:error: resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: 
java.util.concurrent.ExecutionException: 
com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: 
com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for 
details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 27s
Information:11 errors
Information:0 warnings

Android Studio 3.0 RC 2

Beneath answered 28/10, 2017 at 9:16 Comment(2)
See this questionCipher
You can try to run assembleDebug task for identifying problem. For more information please read here https://mcmap.net/q/168117/-exception-aapt2-error-check-logs-for-detailsCousteau
B
113

Update 2 (Follow this approach)

You shouldn't do this now. Instead fix all the errors. This is only a workaround until it's removed. After that, you'll need to fix errors manually anyways.

Try to update your gradle plugin to 3.3.0-alpha06 to check if that fixes your issue.

Update 1:

Non-ascii characters issues have been fixed in AAPT2 and android gradle plugin now (yay!). Instead of disabling AAPT2 now you can just use android gradle plugin version 3.2.0-alpha11 or newer and you should not encounter this error anymore.

Original Answer

Aapt2 is enabled by default when you use android plugin for gradle 3.0.

This is to

improve incremental resource processing

as stated here.

But if you are facing issues with it, you can switch back to previous version by adding this in gradle.properties

android.enableAapt2=false
Burkhart answered 28/10, 2017 at 9:29 Comment(13)
but after it there is an issue with running the androidTest. It gives the error Class not found: "com.app.someapp.TheTestClass"Empty test suite. See here #47970459Matherne
Which gradle.properties? There are three. And it does not work.Aftmost
the one which is at the top(project) level.Burkhart
I get on afterwards compilation: "Error:Non-base feature modules require AAPTv2 to build."Preterition
Konrad, the "Please see here" link has been removed.Pistachio
Doing this in my gradle.properties revealed what the real issue was, which is that I replaced some png images without renaming them. Phew.Syne
after this action i got this msg Process 'command 'D:\Android\sdk\Sdk\build-tools\27.0.3\aapt.exe'' finished with non-zero exit value 1Starofbethlehem
Thanks, you solve my problem!! , open gradle.properties and add this android.enableAapt2=false. My gradle version is 3.0.1Odontalgia
Non-ascii characters issues have been fixed in AAPT2 and android gradle plugin now (yay!). Instead of disabling AAPT2 now you can just use android gradle plugin version 3.2.0-alpha11 or newer and you should not encounter this error anymore.Barbie
'Process 'command 'D:\Android\sdk\Sdk\build-tools\27.0.3\aapt.exe'' finished with non-zero exit value 1' Whats the solution for the above Error??Aglimmer
It works, but I got the message: The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018..Epigynous
This has been deprecated. WARNING: The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018..Fairweather
DO NOT USE THIS! Any disabling of new features WILL still break the project in the future. As Pranav Karnik said, it's deprecated and scheduled for removal: this is only a workaround until it's removed. After that, you'll need to fix errors manually anyways.Bacardi
C
103

UPDATE

A new version of Gradle and Android-gradle-plugin is available that fixes these issues.

build.gradle (top level)

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

gradle-wrapper.properties

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

PREVIOUS ANSWER

If you disable AAPT2 you are just hiding the real issue.

Please be aware that AAPT1might be removed in the future therefore you are forced to use AAPT2. Actually the migration guide isn't hard to follow since you don't see that much changes at the same time this way is future proof.

Element hierarchies in the Android manifest

In previous versions of AAPT, elements nested in incorrect nodes in the Android manifest are either ignored or result in a warning. For example, consider the following sample:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myname.myapplication">
   <application
       ...
       <activity android:name=".MainActivity">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <action android:name="android.intent.action.CUSTOM" />
       </activity>
   </application>
</manifest>

Therefore you must check first if your really follow the correct Manifest structure as showed below.

Manifest file structure

The code snippet below shows the general structure of the manifest file and every element that it can contain. Each element, along with all of its attributes, is fully documented in a separate file.

<manifest>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>
Cipher answered 31/10, 2017 at 3:57 Comment(14)
@Downvoters pls. explain exactly what's wrong with this answer so that I can address?Cipher
Hi Enzokie, I got the same aapt2 exception. What I do is update the compileSdkVersion from 21 to 26, then aapt2 crash. Do you know where I cound found the error log?Necrolatry
@Necrolatry you can check the log in Gradle console, it is like the same as Logcat.Cipher
@Necrolatry incase you can't find the error, feel free to upload the project and message me so that I can check.Cipher
You haven't provided a solution, just a theory behind its cause that may or may not be relevant.Reconstructionist
@Chris-Jr so disabling the Appt2 is a solution? because it makes no sense to use to Gradle 3.0 if you are going to disable its feature. The migration guide is not own word because it is the directly from the documentation itself. You can argue that Appt1 might stay for a little longer but how long?Cipher
@Enzokie, you're absolutely right, that solution isn't future proof, it's a quick fix. I tried to add that to my last comment but 5 minutes had passed so couldn't be edited. You haven't given an answer that addresses his specific error though.Reconstructionist
@Chris-Jr no problem buddy I also use that quick fix before because I thought it was the right answer however it just create a chain of error on some part of my project. I actually experience the same issue as the OP and it turns out that Gradle 3.0 is doing something different I notice that if I did not follow the instruction the annotation processor is not generating properly. Also the docs mentioned some new changes in the xml, it is not a drastic change but that could safely avoid you from trouble (technically this just a generic answer)Cipher
@Cipher It can definitely be a (short term) solution. I want to use Android Studio 3, but I'm using a library that isn't compatible with AAPT2. Hopefully it will be updated soon.Pietra
@Pietra hopefullyCipher
This issue is not completely fixed yet. I'm using android studio 3.3.0 and my gradle distribution file version is 4.10.1. But this problem occurred.Caine
@AhamadullahSaikat are you having similar stacktrace to OP?Cipher
@Cipher Yes. I solved this issue by downgrading classpath 'com.android.tools.build:gradle:3.2.1' and distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zipCaine
Glad to hear :)Cipher
M
21

I had an error in my XML layout. So check your xml layout for errors.

Meehan answered 23/2, 2018 at 20:31 Comment(2)
shouldn't error be a bit more specific in this case?Bridoon
Unfortunately, no @Bridoon . This exact error is thrown if there are special characters in your XML layout strings.Delisadelisle
P
13

Check gradle console tab in android studio (by default in bottom right corner). In my case there were errors like this:

C:\Users\Jozef Bar??k\.gradle\caches\transforms-1\files-1.1\appcompat-v7-25.4.0.aar\d68bb9d2059935a7891196f4dfb81686\res\drawable-hdpi-v4\abc_ic_menu_share_mtrl_alpha.png: error: file not found.

Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
:app:mergeDebugResources FAILED

I solved the issue setting gradle user home to another location without white or special characters:

C:\Android\.gradle

You can configure it setting "Service directory path" in Gradle settings dialog. In my case it was necessary to delete old .gradle directory on previous location and restart android studio.

Prowess answered 4/1, 2018 at 21:51 Comment(3)
for me the problem was the filename got too long when running the build as a service C:\Windows\System32\config\systemprofile\.gradle\.......... set GRADLE_USER_HOME=d:\.gradle fixed the issue (in my case as a System Environment Variable)Kibitzer
Thank you, that helped me solve my issue as I had a latin "é" in my service directory path.Mccloud
After Android Studio 3.1, the Gradle console tab was removed. It's now in the Build tab. Click the 'Toggle View' button (in the build tab on the left, underneath the hammer button) to change view to raw Gradle output to view the real error that's causing the AAPT2 errorPharisaic
Q
8

My problem was due to an image file name ending with .9.png. I changed the ending to .png and the problem disappeared. I got the hint from the stack trace in Gradle console: The top message was "Execution failed for task :app:mergeDebugResources" and the bottom message was "com.android.builder.png.AaptProcess$NotifierProcessOutput.out"

I look forward to the day when Gradle outputs more helpful error messages...

Quintuplet answered 9/1, 2018 at 15:36 Comment(0)
G
7

Having the same issue here. As pointed out by @Izabela Orlowska, this problem is most likely caused by special characters in path (android grandle files, resources etc..).

For me: having ří in folder name caused all the problems. Make sure you do not have any special characters in paths. Disabling AAPT2 is only a temporary "solution". Your project path contains non-ASCII characters android studio

Genisia answered 2/1, 2018 at 16:26 Comment(0)
L
7

I just had this problem when trying to use data bind and declaring the layout tag. I know it is a bit late but for the sake of anyone encountering this problem, What I did to resolve the issue after so many attempts was that on your root layout when you are not using data bind say for example this

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">     </android.support.constraint.ConstraintLayout>

remove the

xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"

and just put it on your layout tag(that is if you are using data binding)

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

</layout>

and hopefully it will work. the android.enableAapt2=false didn't work for me so I have to remove everything and try to figure out why I get the error when I put layout tag and use data binding thus I came up with the solution. Hope it helps

Lieabed answered 3/4, 2018 at 6:39 Comment(2)
Thanks dude! you saved an hour for me.Servais
Thanks dude! You saved two hours for me!Contradance
B
5

Since at some point in the future the support for AAPT(1) will be deprecated, it would be good to identify the reason for the error you reported.
Could you provide the contents of the \app\src\main\res\layout\topic_view_header.xml file? From the question marks it is possible that you are using non-ASCII characters, which AAPT2 still has some trouble with. If it's indeed non-ASCII characters then please follow the bug on https://issuetracker.google.com/68262818.

Update: The issue is fixed in android gradle plugin version 3.2.0-alpha11 or newer.

Barbie answered 30/10, 2017 at 14:22 Comment(3)
Please see here #47971866Matherne
@Konrad 404 ,@izabela still same issue on gradle 4.1Cherian
@AjayPandya that's gradle version, you need to update the android gradle plugin version. In your project's build.gradle file you need to update to have classpath 'com.android.tools.build:gradle:3.2.0-alpha11'.Barbie
H
5

I fixed the ERROR with three steps
1. I checked for the problem SOURCE
2. Provided the correct string/text, it was the CAUSE
3. I cleaned the project, you will find it under BUILD.
My project

Hindoo answered 25/4, 2018 at 13:17 Comment(1)
Thanks helped me to identify my problems!Ossicle
O
4

Important Update

Do not add this line to your project as other answers. Because it is already resolved in newer Gradle versions.

You can update your build gradle version in Project level build.gradle to latest.

buildscript {
    dependencies {
        // choose latest if available
        classpath 'com.android.tools.build:gradle:3.3.0-alpha06'
    }
}

and gradle-wrapper.properties

// choose latest if available
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

That's All! Sync and Run, Bingo!

More info Android Documentation

If you add, you will get an warning android.enableAapt2=false

WARNING: The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018.

Olli answered 20/8, 2018 at 5:14 Comment(5)
This is the best answer ive seen so far, because if you try to disable aapt2 it throws an error at this time of writing, all i had to do was update gradle, and after updates, gradle told me what the actual error was, matter of fact it didn't let me use gradle-4.8 in the gradle-wrapper.properties file, i had to use 4.9 the latest version, also in the dependencies path, i had to use gradle:3.3.0-alpha06Sabra
I'll update the original post, so its easier to follow.Sabra
In which gradle file I have to write android.enableAapt2=false ?Mantelet
@nTri Look only for Solution part of answer, you don't need to add android.enableAapt2=false.Olli
Glad to help you @nTri :)Olli
U
2

I also encountered this error. For me, it was when changing the target SDK from 26 down to 25. I was able to fix the problem by changing the appcompat dependency version from

implementation 'com.android.support:appcompat-v7:26.1.0'

to

implementation 'com.android.support:appcompat-v7:25.4.0'

This will allow the compiler to access the styling attributes that it is currently unable to find. This will actually fix the problem instead of masking the real issue as Enzokie suggested.

Undervest answered 22/11, 2017 at 22:48 Comment(0)
B
2

In my case i was using wrong color code #CC00000 which is invalid because it has 7 digit but color code should have 3 or 6 or 8 digit plus # prefix

Baltic answered 4/1, 2018 at 13:15 Comment(0)
H
2

Disabling the AAPT2 mght cause issue in further development, In my case the error was generated when I created the app icon.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="108dp"
    android:height="108dp"
    android:viewportWidth="Infinity"
    android:viewportHeight="Infinity">
<path android:fillColor="#26A69A"
      android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
      android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>

I solve it by removing this line

    android:viewportWidth="Infinity"
    android:viewportHeight="Infinity"
Hunyadi answered 19/1, 2018 at 2:24 Comment(0)
G
2

As @Izabela Orlowska pointed out: In my case the problem occurred due to some files that could not be found inside the gradle cache folder. (Windows OS)

The default gradle path was inside my user folder. the path contained umlauts and a space. I moved the gradle folder by setting GRADLE_HOME and GRADLE_USER_HOME environment variable to some newly created folder without umlauts or spaces in path. This fixed the problem for me.

Greatgrandaunt answered 24/1, 2018 at 10:39 Comment(0)
E
2

I tried everything suggested on here and many other sites, I eventually figured out that the problem was with Bitdefender blocking aapt....

If you have Bitdefender installed then you need to turn aapt & aapt2 "Application Access" on individually.

Hope this is of use.

Engleman answered 14/2, 2018 at 16:4 Comment(0)
C
2

If you've seen this error after trying to run individual Android implementation tests or test classes (by clicking on the run icon in the gutter) in a Kotlin project in Android Studio 3.0.1, you can get around the error by instead running the full test package (by right-clicking on the test package and choosing "Run tests in...").

There is a known bug in Android Studio 3.0.1 that causes the IDE to run Kotlin implementation tests as regular JUnit tests, which caused the OP's error message to get shown on my machine. The bug is tracked at https://issuetracker.google.com/issues/71056937. It appears to have been fixed in Android Studio 3.1 Canary 7.

Carce answered 25/2, 2018 at 18:45 Comment(0)
H
2

As suggested by others,

android.enableAapt2=false

is the most common solution.

But in my case, the error was due different versions in compileSdkVersion and buildToolsVersion.

Make sure that the major version is maintained the same.

Heres answered 28/2, 2018 at 9:30 Comment(1)
"compileSdkVersion and buildToolsVersion" Is the first thing to checkSingletary
P
2

I was getting this error when the project name was very long, and the location I was saving the project in, added to it. Moving the project to another location so that the file names are not crossing the system limit resolved the error for me.

C:\Users\<UserName>\AndroidStudioProjects\From Github\AdvancedAndroid_Emojify-TLIB.02-Exercise-DetectFaces\AdvancedAndroid_Emojify-TLIB.02-Exercise-DetectFaces\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:error: file not found.
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Papandreou answered 6/3, 2018 at 5:53 Comment(0)
S
2

I have also had such a problem, the original is my computer's system tray this path :

C: \ Users \ 'appear special characters' \ .android appeared in Chinese,

and now I changed the path to :

C: \ Users \ hjc \ .android.

The reason is the problem of special characters.It is for this reason that leads to gravel appt2Exception problems

Stomato answered 7/3, 2018 at 14:8 Comment(1)
This has been fixed now. If you update to android gradle plugin 3.2.0-alpha11 or newer it works with non-ascii characters in the file-path now.Barbie
S
2

I had a very similar problem. It was solved by deleting gradle's cache (~/.gradle/caches on linux), which forced android studio to re download and re generate everything.

Shulamith answered 27/3, 2018 at 19:45 Comment(0)
B
2

Closing the project and restarting android studio fixed this issue for me.

While restarting, android studio notified that it needed to download missing SDKs, so once that was taken care of ,the issue was fixed.

Builtin answered 3/4, 2018 at 4:10 Comment(0)
H
2

I am not sure if this has been answered yet for you but allow me to weigh in. I confronted a similar problem recently and I was able to pinpoint the exact problem from the build tab next to the logcat. My problem was caused by a fontfamily error in the XML. I am using the latest version of Android Studio with the March 2018 update.

Hottentot answered 4/4, 2018 at 13:0 Comment(0)
C
2

Ensure that you use valid file types in your src/main/res/raw directory. In my case I had copied a .mov file along with a bunch of other files into my res/raw directory. I suspect the issue was that aapt was trying to process the .mov file and did not know what to do with it.

Coinage answered 18/4, 2018 at 18:46 Comment(0)
T
2

I had exactly the same issue: After updating to Android Studio 3.1.2 my project wouldn't compile with an AAPT2 error telling me some of my drawables which are referenced by styles.xml could not be found. Disabling AAPT2 isn't a solution anymore, since the setting is deprecated and will be removed at the end of 2018.

Culprit was an empty line just before the xml decleration in a totally unrelated layout.xml file... So the layout.xml file started like this:

//empty line//
<?xml version="1.0" encoding="utf-8"?>

Removed the empty line and everything worked like a charm again. Unbelievable and unlikely, but true.

Android Studio actually gave a warning because the file didn't start with the xml decleration (because of the empty line). But the warning is only visible when the file is opened in the editor.

Tamis answered 3/5, 2018 at 18:18 Comment(0)
F
2

This error message (AAPT2 error: check logs for details ) is not helpful because it doesn't tell you what the real problem is.

In my case, it was due to a missing resource XML drawable file.

error: failed linking file resources.

org.gradle.tooling.BuildException: Failed to process resources, see aapt output above for details.

I only figured out because I undid the changes in the XML file, and this time I got a more helpful message:

error: resource drawable/ic_filter_off (aka com.xxx:drawable/ic_filter_off) not found.

Message{kind=ERROR, text=error: resource drawable/ic_filter_off (aka com.xxx:drawable/ic_filter_off) not found., sources=[C:\code\xxx\app\src\main\res\layout\app_bar_main.xml:69], original message=, tool name=Optional.of(AAPT)}
Feliciafeliciano answered 8/5, 2018 at 18:53 Comment(0)
P
2

In my case the real problem was that after generating Image Asset to generate launcher mipmap icon for my project, the generated file ic_launcher_foreground.xml had error inside (was wrongly generated). There was missing closing xml tag in the end of file, < / vector> was missing.

Pieper answered 11/5, 2018 at 10:54 Comment(0)
K
2

Check and try below things. Issue should be resolved.

  1. First of all check your log from bottom of the build window whether any error related to project showing or not. If error showing then fix all of those. Now build and run again fix all of the error comes up. It will eliminate aapt2 issue without changing android gradle plugin to 3.2.0.

  2. Secondly if there is not any project related error showing in the build log but still showing aapt2 error then you can fix it by following below steps.

Update your android gradle plugin in your project level build.gradle file like below:

classpath 'com.android.tools.build:gradle:3.2.0-alpha13'

Now update android.enableAapt2=true. Then check and build your project.

Any of these steps should work to fix aapt related issues.

Kieserite answered 12/5, 2018 at 4:55 Comment(0)
C
2

If you are using Kotlin getting error because of some mistakes in xml files. In kotlin its very hard to find xml errors, build getting fail simply . To know the exact error log run below command in Android Studio Terminal and it is easy to fix the errors.

./gradlew clean
./gradlew assemble
Countrydance answered 23/5, 2018 at 4:55 Comment(1)
Using these in terminal actually shows the exact error. In my case, it was an empty visibility attr. Thank you!Gook
E
2

I got same error AAPT2 error: check logs for details, and i applied above solutions, as per most common solution, i was opened gradle.properties and add line

android.enableAapt2=false

for solution, but i got an error Process 'command 'D:\Android\sdk\Sdk\build-tools\27.0.3\aapt.exe'' finished with non-zero exit value 1

But after many searches i found that there is problem in layout's xml file that i was repeat lines in layout's xml file which is as below:

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

Remove Repeat lines from xml file and rebuild project and Done.

Elwood answered 26/5, 2018 at 6:48 Comment(0)
S
2

Check following things in your project:

  • Make sure any XML file doesn't have blank space at starting of the file.

  • Make sure that any drawable file doesn't have any issue like capital letters or any special symbols in name.

  • If your aapt2.exe is missing continuously then please scan your full PC, May be there is a virus which is removing adb.exp or aapt2.exe

Hope you will get solution.

Samos answered 4/7, 2018 at 12:2 Comment(0)
P
2

The Resource Exception means there is an error with your resources, any resource folder file is corrupted, try to open all images in drawable folder to see if these are opening fine.

There is a good command to check for corrupted resource pngs.

f -name "*.png" | xargs -L 1 -I{} file  -I {} | grep -v 'image/png; charset=binary$'
Premedical answered 25/7, 2018 at 6:7 Comment(0)
H
2

Check if any of your new XML files has an issue. Go to Android issues and see if there are XML files there. However, the error doesn't show on the right XML file that has the problem.

In my case, I added two headers in the same XML file.

Something like that:

Hinda answered 31/7, 2018 at 16:34 Comment(0)
C
2

For AAPT2 error: check logs for details or error: failed linking file resources. errors:

Check your .xml files that contains android:background="" and remove this empty attribute can solve your problem.

Caviness answered 26/9, 2018 at 19:41 Comment(0)
N
2

I also face this problem. "AAPT2 error: check logs for details" with studio version 3.1.2 when first time building app.

I was using 'com.android.support:appcompat-v7:26.1.0'and some styles were not found when i see the error logs. So changed it to 'com.android.support:appcompat-v7:25.3.1' from my working project and issue got resolved.

Try it.

If still you face problem try for v7:26+ in place of exact version. This will definitely resolve issue.

Nealon answered 5/10, 2018 at 7:53 Comment(0)
W
2

Don`t use this android.enableAapt2=false, this is not a solution . find out the error which is exactly show in your Build Output box , click on Toggle view to find exact error or exception use

 compileSdkVersion 28
 buildToolsVersion "28.0.3" 

use this on gradel-wrapper:

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

and follow the instruction delete or update external library or dependencies

Wayless answered 2/11, 2018 at 7:59 Comment(0)
C
2

I solved this issue by downgrading classpath 'com.android.tools.build:gradle:3.2.1' and distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

Caine answered 23/1, 2019 at 6:32 Comment(0)
A
2

Add build.gradle in-app level aaptOptions { cruncherEnabled = false }

Akerboom answered 6/2, 2019 at 7:59 Comment(0)
N
2

Delete the .idea folder, and then try again. Make sure that you are using an open network.

Nealon answered 22/2, 2019 at 0:51 Comment(1)
Where is this .idea folder?Lockridge
H
2
  • Most probably this happen because of some silly mistake in layout file
  • in my case case I have copied a textview from another project but the backgroundColor resource was not available in my current project
  • The thing that it was not showing the error at run time but gives above error while compile time.
  • You can find out where the exact error in your xml by following the process:

Click on the Gradle tab in right side of Android Studio -> Open the projects build directory as shown in below image -> Run the assembleDebug

-- The error will be shown like in below image

enter image description here

Holp answered 1/6, 2019 at 11:32 Comment(0)
D
1

Looks like a resources related error. I would start there.

I got this ("Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details") first time related to pictures. Resize solved it. Or another time just repaired the links to resources.

Dancette answered 17/11, 2017 at 13:7 Comment(0)
K
1

Sometimes ! be careful with property depth of the image ! and name for image

exemple : ic_xxxxx_xxxx - Copie

enter image description here

Keheley answered 19/11, 2017 at 9:12 Comment(0)
G
1

I got this error

com.android.tools.aapt2.Aapt2Exception: AAPT2 error 

due to wrong filename of one of my /drawable item in layer-list.

And I resolved it by changing the filename to correct one.

Gylys answered 22/12, 2017 at 15:45 Comment(0)
T
1

In my case it was fixed by adding a reference to the constraint-layout package

    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
Tumble answered 12/6, 2018 at 4:52 Comment(0)
H
1

In my case removing the pre-existing build folder and retrying solved the problem.

Harding answered 29/3, 2019 at 14:15 Comment(0)
V
1

I was using on wrong way an coordinator layout attribute, I removed that and it works. Check your layout

app:layout_constraintVertical_bias="parent"

That should be a numeric value not literal :/ tiny mistake

Valance answered 21/5, 2019 at 21:2 Comment(0)
I
1

I encountered the same issue, searched on google, tried a lot of solutions, none worked.
Until I found the golden key of solving this: ./gradlew assembleDebug.

Try this command in git bash, the console will tell exactly which line has errors.
Then you improve it, and run the command again, until compilation succeeds.

Ironsmith answered 8/8, 2019 at 6:32 Comment(0)
M
0

I had this issue

AAPT2 error: check logs for details

because i have added Quotation Marks(') to my string file without using Backslash(\)

error text

 <string name="no_internet">You don't have internet connection </string>

fixed text

<string name="no_internet">You don\'t have internet connection </string>

so, check special character correctly added to your string file

Messily answered 18/6, 2019 at 5:1 Comment(0)
C
0

In my case I have update compile SDK and build SDK version to 30 and added

 requestLegacyPermission=true 

in android manifest file, as I was accessing the storage for reading and writing. later when I edited the compile SDK and build SDK version and get back to version 26 then I forgot to remove

requestLegacyPermission=true 

in Manifest file.

Reason:

requestLegacyPermission was introduced in Android 10 so that's the reason Manifest was not recognizing this as I updated Compile SDK and Build SDK to 26.

Coelenteron answered 1/1, 2021 at 4:58 Comment(0)
N
0

This worked for me.

Its gradle issue. Upgrade your gradle to version 6

https://services.gradle.org/distributions/gradle-6.5-all.zip

If you using cordova then update android version to 9

Ex :  cordova platform add [email protected]
Noella answered 23/9, 2021 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.