PNG文件导致的Gradle Build Error

今天琢磨着把Android Studio升级到2.2.0 Preview版本试一试,然而遇上了很奇怪的错误,有关res文件。

Gradle Console Log如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72330Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2330Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV132330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2330Library UP-TO-DATE
:app:prepareComGithubAfollestadMaterialDialogsCore0857Library UP-TO-DATE
:app:prepareComLuolcDevLitesyllabusview102Library UP-TO-DATE
:app:prepareInSrainCubeUltraPtr1011Library UP-TO-DATE
:app:prepareMeZhanghaiAndroidMaterialprogressbarLibrary115Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
AAPT: /Users/LuoLiangchen/AndroidStudioProjects/PKUHelper/app/src/main/res/drawable-xhdpi/ipgw_button_1_colored.png: libpng warning: iCCP: out-of-date sRGB profile with no signature
AAPT: /Users/LuoLiangchen/AndroidStudioProjects/PKUHelper/app/src/main/res/drawable-mdpi/icon_course.png: libpng warning: iCCP: out-of-date sRGB profile with no signature

AAPT: /Users/LuoLiangchen/AndroidStudioProjects/PKUHelper/app/src/main/res/drawable-xhdpi/ipgw_button_2_colored.png: libpng warning: iCCP: out-of-date sRGB profile with no signature
AAPT: /Users/LuoLiangchen/AndroidStudioProjects/PKUHelper/app/src/main/res/drawable-mdpi/error.png: libpng warning: cHRM: invalid chromaticities
AAPT: /Users/LuoLiangchen/AndroidStudioProjects/PKUHelper/app/src/main/res/drawable-mdpi/success.png: libpng warning: cHRM: invalid chromaticities
AAPT: libpng error: Not a PNG file
Error: java.lang.RuntimeException: Some file crunching failed, see logs for details
:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: java.lang.RuntimeException: Some file crunching failed, see logs for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.486 secs

关键点在于31行开始的问题,看样子竟然是资源文件出了错。

StackOverflow之,原因如下:

This is due to adding an image in drawable which has some extension like(.jpg) and you have changed or saved that to a .png format(this error will occur while changing the image format manually without using a Editor tool). Android studio will throws a error while compiling the resource package using AAPT(Android Asset Packaging Tool), so all you need to do is use some Image Editor tools like “gimp or paint” to save the Extension accordingly. Rebuild your project once everything is done.

所以是因为这原本是个jpg文件,然后手动改了后缀为png,Gradle Build的时候就报错了。
不过很奇怪为什么老版本的Android Studio没有这个问题……

解决方法,用任意一个图片编辑软件(我用的自己使得最多的Sketch),把图拖进去,重新以PNG格式export即可。