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

后端 未结 30 1479
野的像风
野的像风 2020-11-22 12:51

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         


        
相关标签:
30条回答
  • 2020-11-22 13:48

    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)}
    
    0 讨论(0)
  • 2020-11-22 13:49

    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.

    0 讨论(0)
  • 2020-11-22 13:49

    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.

    0 讨论(0)
  • 2020-11-22 13:50

    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
    
    0 讨论(0)
  • 2020-11-22 13:50

    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.

    0 讨论(0)
  • 2020-11-22 13:52

    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
    
    0 讨论(0)
提交回复
热议问题