Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is AAPT2?

AAPT2 (Android Asset Packaging Tool) is a build tool that Android Studio and Android Gradle Plugin use to compile and package your app's resources. AAPT2 parses, indexes, and compiles the resources into a binary format that is optimized for the Android platform. Android Gradle Plugin 3.0.


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

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 had an error in my XML layout. So check your xml layout for errors.


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.


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