Upgraded to Android Studio 1.0 & Gradle 1.0.0, aapt makes PNG images larger if pre-optimized

别来无恙 提交于 2019-12-23 01:21:35

问题


I performed an upgrade to Android Studio 1.0 & Gradle 1.0.0 today, from Android Studio 0.86 & Gradle 0.13. Prior to the upgrade, I was using "runProguard = true" option in my release builds extensively, to reduce my APK size to just under 50 MB, to meet Google Play Store's APK size restrictions.

However, with the new Android Studio 1.0 / Gradle 1.0.0 with "minifyEnabled = true", I am seeing resulting APKs at 55.6 MB, which is significantly larger than before. The debug build APKs are resulting in 55.6 MB as well, leaving me to conclude that the minifyEnabled option isn't actually working.

I've updated my Gradle configuration to work with the new Gradle version and is listed below:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.1'

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 21
}

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        zipAlignEnabled true
        signingConfig signingConfigs.release
        }
    }
}

dependencies {
   compile 'com.android.support:appcompat-v7:21.+'
   compile 'it.sephiroth.android.library.picasso:picasso:2.3.4.3'
}

As far as I can see, everything seems to be okay with the build.gradle file, but minifyEnabled just doesn't seem to work. What's strange is that there are no compilation errors reported when I generate the release build. Does anyone have any ideas on how to get minifyEnabled to work?


EDIT (12/10/2014):

Alright, it appears that this issue is not related to minifyEnabled at all, but to an older bug with aapt that was previously resolved with Gradle 0.9.1, where aapt would increase the size of PNG files if they were already pre-optimized.

http://tools.android.com/tech-docs/new-build-system

The bug has resurfaced with Gradle 1.0.0. This bug can be reproduced by doing the following:

  1. Optimize PNG files with TinyPNG or other PNG optimization tools.
  2. Use Android Studio 1.0 with Gradle 1.0.0.
  3. Compile Android project with or without aaptOptions newPNG flag.
  4. Open APK file and compare PNG files against original PNG files for size.

The issue has been reported on the AOSP tracker and they seem to be aware of it: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=tinyPNG&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=65335

FYI, this post should probably be merged with this previous StackOverflow post, as it is exactly this same old problem: Export signed app without "optimizing" png images

来源:https://stackoverflow.com/questions/27369959/upgraded-to-android-studio-1-0-gradle-1-0-0-aapt-makes-png-images-larger-if-p

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