AAPT2 error: this error happened as soon as i updated my android studio to the latest version

风流意气都作罢 提交于 2019-12-05 18:51:09

try to execute :

./gradlew clean
./gradlew assemble

if doesn't work try w Clean and Rebuild the project. Finally, go to

Files > Invalidate caches

The problem is with the PNG files it might be corrupted. Sometimes the images are listed as PNG but are not real PNGs.

You can get the list of such images by typing the following code in android terminal

find . -type f -name "*.png" | xargs -L 1 -I{} file  -I {} | grep -v 'image/png; charset=binary$' 

After that, you can convert those to PNG and try again.

Don't add this android.enableAapt2=false as it is deprecated and won't be supported.

Adnan Ali

Try to change the compileSdkVersion to: compileSdkVersion 28 and targetSdkVersion 26 This works for me.

I just had this problem when trying to use data bind and declaring the layout tag. What I did to resolve the issue after so many attempts was that on your root layout when you are not using data bind say for example this

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">     </android.support.constraint.ConstraintLayout>

remove the

xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"

and just put it on your layout tag(that is if you are using data binding)

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

</layout>

and hopefully it will work. the android.enableAapt2=false didn't work for me so I have to remove everything and try to figure out why I get the error when I put layout tag and use data binding thus I came up with the solution. Hope it helps

It happened with me when I updated Android studio to 3.4.0. I did change in Project level build.gradle file...

dependencies {
        //classpath 'com.android.tools.build:gradle:3.4.0'    //Previus default set up

       classpath 'com.android.tools.build:gradle:3.3.1' // Now working fine

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!