Error:com.android.tools.aapt2.Aapt2Exception: AAPT

2018-12-31 17:47发布

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

30条回答
还给你的自由
2楼-- · 2018-12-31 18:25

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'
查看更多
高级女魔头
3楼-- · 2018-12-31 18:26

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
查看更多
与风俱净
4楼-- · 2018-12-31 18:27

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

exemple : ic_xxxxx_xxxx - Copie

enter image description here

查看更多
浅入江南
5楼-- · 2018-12-31 18:30

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.

查看更多
初与友歌
6楼-- · 2018-12-31 18:30

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.

查看更多
路过你的时光
7楼-- · 2018-12-31 18:31

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.

查看更多
登录 后发表回答