[android] Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

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

This question is related to android android-gradle-plugin

The answer is


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.


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.


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


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.


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.


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.


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


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


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.


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.


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.


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"

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.


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$'

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.


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.


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.


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:


  • 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


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


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


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

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 rĂ­ 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


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


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


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.


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'

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

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.


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


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.


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


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.


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.


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.


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


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.


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


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.


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.


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

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

exemple : ic_xxxxx_xxxx - Copie

enter image description here


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


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


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>

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.


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.


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)}