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:42

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:

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.

查看更多
刘海飞了
3楼-- · 2018-12-31 18:42

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$'
查看更多
泛滥B
4楼-- · 2018-12-31 18:43

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.

查看更多
有味是清欢
5楼-- · 2018-12-31 18:43

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"
查看更多
ら面具成の殇う
6楼-- · 2018-12-31 18:46

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.

查看更多
呛了眼睛熬了心
7楼-- · 2018-12-31 18:48

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:

查看更多
登录 后发表回答