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

halfer
  • 19,824
  • 17
  • 99
  • 186
Zeeshan Ali
  • 2,211
  • 4
  • 18
  • 25
  • See this [question](https://stackoverflow.com/q/46976562/5217712) – Enzokie Oct 28 '17 at 09:33
  • You can try to run assembleDebug task for identifying problem. For more information please read here https://stackoverflow.com/a/47941174/1573414 – AnteGemini Nov 06 '18 at 16:23

49 Answers49

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
Yash
  • 5,225
  • 4
  • 32
  • 65
  • 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 https://stackoverflow.com/questions/47969959/class-not-found-empty-test-suite-in-androidtest-using-android-studio-3-0-1-roo – K.Os Dec 25 '17 at 19:00
  • Which gradle.properties? There are three. And it does not work. – Niklas Rosencrantz Dec 28 '17 at 21:39
  • the one which is at the top(project) level. – Yash Dec 29 '17 at 08:29
  • I get on afterwards compilation: "Error:Non-base feature modules require AAPTv2 to build." – Zon Jan 11 '18 at 16:23
  • Konrad, the "Please see here" link has been removed. – Bryon Nicoson Mar 27 '18 at 14:46
  • Doing this in my gradle.properties revealed what the real issue was, which is that I replaced some png images without renaming them. Phew. – Julian K Apr 10 '18 at 03:44
  • 29
    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 1` – SAYE Apr 24 '18 at 11:29
  • Thanks, you solve my problem!! , open gradle.properties and add this android.enableAapt2=false. My gradle version is 3.0.1 – Exel Staderlin May 03 '18 at 09:32
  • 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. – Izabela Orlowska May 29 '18 at 12:35
  • '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?? – Ragavendra M Jun 06 '18 at 18:12
  • 2
    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..` – Michał Terczyński Jul 09 '18 at 21:42
  • 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..``` – Pranav Karnik Jan 24 '19 at 06:03
  • 1
    ***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. – Zoe Feb 26 '19 at 11:26
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>
Amit yadav
  • 13
  • 1
  • 4
Enzokie
  • 7,365
  • 6
  • 33
  • 39
  • 7
    @Downvoters pls. explain exactly what's wrong with this answer so that I can address? – Enzokie Nov 17 '17 at 00:33
  • 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? – Ninja Nov 17 '17 at 07:31
  • @Ninja you can check the log in Gradle console, it is like the same as Logcat. – Enzokie Nov 17 '17 at 07:46
  • @Ninja incase you can't find the error, feel free to upload the project and message me so that I can check. – Enzokie Nov 17 '17 at 07:52
  • 3
    You haven't provided a solution, just a theory behind its cause that may or may not be relevant. – Chris - Jr Jan 30 '18 at 09:45
  • @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? – Enzokie Jan 30 '18 at 09:58
  • @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. – Chris - Jr Jan 30 '18 at 10:04
  • @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) – Enzokie Jan 30 '18 at 10:10
  • @Enzokie 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. – nasch Jan 31 '18 at 18:50
  • @nasch hopefully – Enzokie Feb 01 '18 at 01:38
  • 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. – Ahamadullah Saikat Jan 22 '19 at 15:32
  • 1
    @AhamadullahSaikat are you having similar stacktrace to OP? – Enzokie Jan 23 '19 at 01:31
  • @Enzokie 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.zip – Ahamadullah Saikat Jan 23 '19 at 06:29
  • Glad to hear :) – Enzokie Jan 23 '19 at 06:32
21

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

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
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.

Jozef
  • 1,154
  • 11
  • 7
  • 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) – Marc Feb 09 '18 at 16:23
  • Thank you, that helped me solve my issue as I had a latin "é" in my service directory path. – Jean-Sébastien Gervais May 21 '18 at 15:46
  • 1
    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 error – georgiecasey Apr 23 '19 at 16:27
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...

Samil
  • 958
  • 1
  • 17
  • 20
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

Jiří
  • 415
  • 6
  • 16
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

CodeAndWave
  • 1,586
  • 3
  • 23
  • 33
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.

Izabela Orlowska
  • 7,431
  • 2
  • 20
  • 33
  • Please see here https://stackoverflow.com/questions/47971366/aapt2-error-check-logs-for-details-after-workround-the-androidtest-not-working – K.Os Dec 25 '17 at 19:15
  • @Konrad 404 ,@izabela still same issue on gradle 4.1 – Ajay Pandya May 28 '18 at 10:54
  • @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'`. – Izabela Orlowska May 29 '18 at 11:58
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

Bukunmi
  • 2,504
  • 1
  • 18
  • 15
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.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • 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-alpha06 – Kingston Fortune Aug 22 '18 at 07:26
  • I'll update the original post, so its easier to follow. – Kingston Fortune Aug 22 '18 at 07:27
  • In which gradle file I have to write *android.enableAapt2=false* ? – Niki Nov 02 '18 at 05:27
  • @nTri Look only for Solution part of answer, you don't need to add `android.enableAapt2=false`. – Khemraj Sharma Nov 02 '18 at 05:28
  • Glad to help you @nTri :) – Khemraj Sharma Nov 02 '18 at 05:53
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.

hlbaker
  • 21
  • 2
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

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
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"
TABZ
  • 125
  • 12
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.

Robin J
  • 156
  • 5
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.

mcadamm4
  • 45
  • 6
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.

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.

VickyAbishek
  • 53
  • 1
  • 6
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
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
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

  • 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. – Izabela Orlowska May 10 '18 at 15:30
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.

Quinn
  • 21
  • 3
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.

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.

Beast77
  • 193
  • 1
  • 17
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.

Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
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.

Andy
  • 151
  • 9
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)}
live-love
  • 48,840
  • 22
  • 240
  • 204
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.

user3098756
  • 340
  • 4
  • 10
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.

0xAliHn
  • 18,390
  • 23
  • 91
  • 111
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
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
  • Using these in terminal actually shows the exact error. In my case, it was an empty visibility attr. Thank you! – Rami Jemli Dec 26 '18 at 05:02
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.

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.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
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$'
garry
  • 419
  • 5
  • 10
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:

André Luiz Reis
  • 2,273
  • 21
  • 14
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.

MarsPeople
  • 1,772
  • 18
  • 30
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.

sudhanshu
  • 409
  • 1
  • 5
  • 12
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

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

Ahamadullah Saikat
  • 4,437
  • 42
  • 39
2

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

Vishal Dasadiya
  • 2,585
  • 1
  • 14
  • 11
2

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

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
sudhanshu
  • 409
  • 1
  • 5
  • 12
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

tejraj
  • 300
  • 2
  • 4
  • 16
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.

Rares Serban
  • 151
  • 3
  • 9
1

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

exemple : ic_xxxxx_xxxx - Copie

enter image description here

Croid
  • 111
  • 5
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.

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'
Jim Factor
  • 1,465
  • 1
  • 15
  • 24
1

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

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
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

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.

MadHatter
  • 301
  • 3
  • 12
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

damith alahakoon
  • 270
  • 4
  • 14
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.

Zurmati
  • 108
  • 8
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 android@9.0.0
Anand_5050
  • 1,019
  • 2
  • 10
  • 23