Android Gradle Project upgrading build tools to 21.0.1: aapt throws Exception

孤街浪徒 提交于 2019-11-28 03:38:52
Binoy Babu

This is caused by a faulty aapt. There was a similar problem in 21.0.0 too (Error Code: -1073741819). You need to update build-tools again to fix it.

  • Open SDK manager and install build-tools 21.1.2.

  • Then change your build.gradle so that it looks like this.

    apply plugin: 'com.android.application'
        android {
            compileSdkVersion 21
            buildToolsVersion "21.1.2"
    

Replace version numbers with the most recent ones as necessary.

Old buildToolsVersion 21.0.2, recommended version is 21.1.2 or later

This worked for me:

It's metadata added by tools like Photoshop that isn't even honored by Android. Strip it.

brew install exiftool
find . -path '*src/main/res/*' -name '*.png' -exec exiftool -overwrite_original -all= {} \;

Source: https://groups.google.com/forum/#!msg/adt-dev/rjTQ_STR3OE/-UcNQRISTKsJ

P.S. Tested on Mac only.

Warnings about libpng are reported here but can be ignored

https://code.google.com/p/android/issues/detail?id=77704

Project Member says the newer libpng they built against is stricter about the color profile. They will fix this in an upcoming release, but this shouldn't be an issue.

And 21.0.2 solves other issues.

I found a way to remove the color profile from png files to avoid this warning by using pngcrush Wikipedia about pngcrush.

If you are working on MacOS you can also use a tool called ImageOptim to run pngcrush and replace the stripped .png files on the fly.

21.0.1 breaks my project as well - aapt will not add any string resource to the APK. Reverted back to 20.0.0, by editing project.config:

sdk.buildtools=20.0.0

I had the same problem with build tools 21.0.0, but after updating to 21.0.1 it has been fixed.

If for some reason it is not practical to manually strip the meta data from the files you can disable the use of the new and more strict png crusher by setting the following in your build.gradle.

aaptOptions.useNewCruncher = false

I was getting the same warnings and aapt was getting stuck even with build tools 22.0.1.I ticked the option Compile independent modules in parallel in settings>compiler which resulted in more than one instance of aapt running and build was successful.

remove the com.android.support:appcompat-v7:xxx dependency

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