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

后端 未结 30 1459
野的像风
野的像风 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:53

    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...

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

    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.

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

    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.

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

    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.

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

    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

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

    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.

    0 讨论(0)
提交回复
热议问题