Android Gradle 项目将构建工具升级到 21.0.1:aapt 抛出异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26446610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Gradle Project upgrading build tools to 21.0.1: aapt throws Exception
提问by dfritsi
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.
我们有一个 android gradle 项目。今天我想将android构建工具版本从20升级到21.0.1,但现在aapt失败了。
* 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.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.
我修复了这些问题,但 appcompat-v7 库中还有 6 个。
If I revert the build tools version to 20 everything works fine.
如果我将构建工具版本恢复为 20,一切正常。
Has anyone came across this problem?
有没有人遇到过这个问题?
采纳答案by 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.
这是一个故障引起的aapt
。21.0.0 也有类似的问题 ( Error Code: -1073741819
)。您需要build-tools
再次更新以修复它。
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"
打开 SDK 管理器并安装
build-tools 21.1.2
.然后更改您的 build.gradle 使其看起来像这样。
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
旧的buildToolsVersion
21.0.2,推荐版本为 21.1.2 或更高版本
回答by marius bardan
This worked for me:
这对我有用:
It's metadata added by tools like Photoshop that isn't even honored by Android. Strip it.
它是由 Photoshop 之类的工具添加的元数据,而 Android 甚至都不尊重它。剥它。
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
来源:https: //groups.google.com/forum/#!msg/ adt-dev/ rjTQ_STR3OE/-UcNQRISKsJ
P.S. Tested on Mac only.
PS 仅在 Mac 上测试。
回答by albodelu
Warnings about libpng are reported here but can be ignored
此处报告了有关 libpng 的警告,但可以忽略
https://code.google.com/p/android/issues/detail?id=77704
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.
项目成员说他们构建的新 libpng 对颜色配置文件更严格。他们将在即将发布的版本中修复此问题,但这应该不是问题。
And 21.0.2 solves other issues.
21.0.2 解决了其他问题。
回答by Noya
I found a way to remove the color profile from png files to avoid this warning by using pngcrush Wikipedia about pngcrush.
我找到了一种从 png 文件中删除颜色配置文件的方法,通过使用 pngcrush Wikipedia about pngcrush来避免此警告。
If you are working on MacOS you can also use a tool called ImageOptimto run pngcrush and replace the stripped .png files on the fly.
如果您在 MacOS 上工作,您还可以使用名为ImageOptim的工具运行 pngcrush 并动态替换剥离的 .png 文件。
回答by Vaiden
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:
21.0.1 也破坏了我的项目 - aapt 不会向 APK 添加任何字符串资源。通过编辑project.config恢复到 20.0.0 :
sdk.buildtools=20.0.0
回答by MrBrightside
I had the same problem with build tools 21.0.0, but after updating to 21.0.1 it has been fixed.
我在构建工具 21.0.0 上遇到了同样的问题,但在更新到 21.0.1 后它已得到修复。
回答by blunden
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.
如果由于某种原因从文件中手动剥离元数据不切实际,您可以通过在 build.gradle 中设置以下内容来禁用新的更严格的 png 粉碎器的使用。
aaptOptions.useNewCruncher = false
回答by Prasenjeet S.
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.
我收到了同样的警告,即使使用构建工具 22.0.1,aapt 也卡住了。我在设置>编译器中勾选了并行编译独立模块选项,这导致 aapt 运行不止一个实例并且构建成功。
回答by Houny Chang
remove the com.android.support:appcompat-v7:xxx
dependency
移除com.android.support:appcompat-v7:xxx
依赖