Export signed app without “optimizing” png images

让人想犯罪 __ 提交于 2019-12-01 00:51:55

问题


When I export an apk from eclipse, it compresses all of the png images. For example, one 4.6 KB png became 2.15 KB inside the apk. However I prefer to optimize png files using tinypng before the apk is built, which makes much smaller files. The same 4.6 KB png became 746 B using tinypng. When building the apk, compression ran on my 746 B png making it 1.6 KB.

Is there any way to disable this optimization for future builds?


回答1:


In your project build.xml ANT file you can override the -crunch task of the SDK, thus avoiding PNG compression, as you previously compressed them:

<target name="-crunch">
    <echo message="Skipping PNG optimization"/>
</target>



回答2:


Google recently introduced a new PNG processor in aapt 0.9.1 in the Android SDK Build Tools that fixes this issue of increased PNG sizes after aapt optimization.

With this update, it is now possible for Android Studio and Gradle to switch between the PNG processors with the following change in your build.gradle configuration file:

android {
    ...
    aaptOptions.useAaptPngCruncher = false
}

By adding this line, aapt uses the new PNG processor in which it checks to see if the "optimized" PNG files are smaller than the original PNG files. I was able to reduce 4.8 MB in my compiled APK and have not encountered any bugs/issues with the new build configuration.




回答3:


Since Gradle Android plugin 1.0.0:

android {
...
  aaptOptions {
    useNewCruncher false
  }
....
}



回答4:


Change the image file extension. For example: renaming someImage.png to someImage.jet worked for me. You can try this.




回答5:


Optimize the files using tinypng before importing them into the project.



来源:https://stackoverflow.com/questions/22219439/export-signed-app-without-optimizing-png-images

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