60

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?

dfritsi
  • 1,224
  • 3
  • 14
  • 24
  • It seems this has been already reported: https://code.google.com/p/android/issues/detail?id=77629 – dfritsi Oct 19 '14 at 02:24
  • 1
    Be aware that there are several different but related bugs in AAPT; that bug report is kind of messy. Your error isn't the main one that was reported where it was returning error -1073741819. Please follow up, and if the bug is closed as being fixed and you're still having problems, please open a new bug. – Scott Barta Oct 19 '14 at 14:15
  • Show your build.gradle – Jared Burrows Oct 21 '14 at 02:30

9 Answers9

40

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.

marius bardan
  • 4,962
  • 4
  • 29
  • 32
  • 2
    The actual command (from the provided link) is `find . -path '*src/main/res/*' -name '*.png' -exec exiftool -overwrite_original -all= {} \;` The command doesn't work without the `*` in `path` – Jedidja Jul 13 '15 at 13:16
  • Where should I put this lines? – Mann Aug 13 '15 at 06:16
  • terminal. 'cd' to your root project folder and paste the command. – marius bardan Aug 13 '15 at 08:27
  • Hi, I have try above mention command. But its not getting it. I got response that: FIND: Parameter format not correct Please let me know how to execute it. – Shreyash Mahajan Dec 25 '15 at 13:02
  • Im on mac and didn't work for me, I used `find ./ -name '*.png' | xargs -L 1 -I '{}' exiftool -overwrite_original -all= '{}'` instead. Thanks – kevinkl3 Jan 30 '16 at 00:01
  • For ubuntu `exiftool` is available. Install using `sudo apt-get install exiftool` and tried the find command. its working. – Mahendran Sakkarai Feb 13 '16 at 10:08
  • It also works with [TinyPNG](https://tinypng.com/), an online (destructive) minifier. – bgondy Feb 16 '16 at 15:52
38

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

Charuක
  • 12,953
  • 5
  • 50
  • 88
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
14

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.

albodelu
  • 7,931
  • 7
  • 41
  • 84
5

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.

Noya
  • 3,879
  • 3
  • 26
  • 32
  • 1
    ater installing it (`apt-get install pngcrush` on ubuntu) you can run it like this: `find . -path '*src/main/res /*' -name '*.png' -exec bash -c 'pngcrush $0 ${0}' {} \;` – SanThee Oct 08 '15 at 23:00
2

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
Vaiden
  • 15,728
  • 7
  • 61
  • 91
1

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

MrBrightside
  • 2,669
  • 3
  • 17
  • 24
1

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
blunden
  • 429
  • 3
  • 10
0

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.

-4

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

Houny Chang
  • 120
  • 2
  • 6