Disable Android resource / image / PNG optimization

后端 未结 6 1054
滥情空心
滥情空心 2020-12-14 01:56

How do I prevent the Android \"build process\" from optimizing .png images?

I have an Android project with the following res directories:

- /res/
- /         


        
6条回答
  •  生来不讨喜
    2020-12-14 02:44

    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 & 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.

    UPDATE: This has been deprecated in later versions of Android Studio. Please refer to the answer provided by ChrisG.

提交回复
热议问题