简体   繁体   中英

AAPT2 Compile time error Android Studio

I've been using Android Studio perfectly well for a long time now but when I tried using CardView in my layout file.

Information:Gradle tasks [:app:assembleDebug]
/Users/professori/.gradle/caches/transforms-1/files-1.1/cardview-v7-25.0.0.aar/1cf3ea204bf2d379f4a71d608f48a715/res/values/values.xml
Error:(18, 5) error: expected color reference but got (raw string) #000t.
/Users/professori/Projects/house/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Error:(2146) expected color reference but got (raw string) #000t.
Error:failed linking references.
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 19s
Information:7 errors
Information:0 warnings
Information:See complete output in console

I am using buildToolsVersion 27.0.1 and v26.1.0 of the respective support libraries. My gradle version is 3.0.1.

I have tried cleaning the project multiple times and even restarting Android Studio but it hasn't helped. Some StackOverflow answers suggest disabling aapt2 in gradle.properties but that just brings some more problems I'd rather not get into.

Is there a permanent way of getting rid of this problem? It's now happened twice in 2 separate projects I'm working on.

I think there is a problem with the color code You are using "#000t" use a correct color code after rebuild it, this will work if not then try below solutions

1:- remove all unnecessary XML files from your code

2:- Reopen and Check XML files

clean and Rebuild Project

If there is Still Problem

Go to your gradle.properties write the below code

android.enableAapt2=false 

and then Go to your build.gradle(app) write the below code and Sync your project

aaptOptions {
        cruncherEnabled = false
    }

喜欢这张图片

Note android.enableAapt2=false is deprecated, and will be removed by the end of 2018, so this doesn't solve the problem, is just a temporary workaround

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM