Android Gradle Project upgrading build tools to 21

2019-01-16 08:12发布

We have an android gradle project. Today I wanted to upgrade the android build tools version from 20 to 21.0.1, but now the aapt is failing.

* What went wrong:
Execution failed for task ':myproject-android:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        c:\_DEVELOP\AndroidSDK\sdk\build-tools\21.0.1\aapt.exe package -f --no-crunch -I c:\_DEVELOP\AndroidSDK\sdk\platforms\android-16\android.jar -M D:\_MY_PROJECT\trunk\myproject_bin\gradle\build\re
lease\myproject-android\intermediates\manifests\full\debug\AndroidManifest.xml -S D:\_MY_PROJECT\trunk\myproject_bin\gradle\build\release\myproject-android\intermediates\res\debug -A D:\_MY_PROJECT\tr
unk\myproject_bin\gradle\build\release\myproject-android\intermediates\assets\debug -m -J D:\_MY_PROJECT\trunk\myproject_bin\gradle\build\release\myproject-android\generated\source\r\debug -F D:\_PIVOSC
ORE_P4\trunk\myproject_bin\gradle\build\release\myproject-android\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.myproject.app -0 apk --output-text-symbols D:\_MY_PROJECT\trunk\
myproject_bin\gradle\build\release\myproject-android\intermediates\symbols\debug
Error Code:
        255

I had some warnings saying:

libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

I fixed those, but there are 6 more in the appcompat-v7 library.

If I revert the build tools version to 20 everything works fine.

Has anyone came across this problem?

9条回答
【Aperson】
2楼-- · 2019-01-16 08:20

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.

查看更多
贪生不怕死
3楼-- · 2019-01-16 08:27

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
查看更多
一夜七次
4楼-- · 2019-01-16 08:29

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.

查看更多
成全新的幸福
5楼-- · 2019-01-16 08:31

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

查看更多
Explosion°爆炸
6楼-- · 2019-01-16 08:33

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

查看更多
SAY GOODBYE
7楼-- · 2019-01-16 08:40

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.

查看更多
登录 后发表回答