3

I am trying to reduce my apk size (because google play services increased size of my app from 65kb to 5MB) using shrink as told in this web: http://tools.android.com/tech-docs/new-build-system/resource-shrinking

i added minifyEnabled true and shrinkResources true

The problem is that as told in that web this should be displayed in gradle log:

:android:shrinkDebugResources
Removed unused resources: Binary resource data reduced from 2570KB to 1711KB: Removed 33%

But nothing is displayed in gradle log.... only this:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportSupportV42100Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds6587Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase6587Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig 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 UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
:app:dexDebug
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
:app:zipalignDebug
:app:assembleDebug

BUILD SUCCESSFUL

Total time: 37.258 sec

this is my code:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 14
        targetSdkVersion 19
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    dependencies {
        compile 'com.google.android.gms:play-services-ads:6.5.87'
    }
}
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • 6
    Your Gradle output is from a `debug` build. Your rules are in your `release` build type. Do a `release` build to see whether or not your rules are working. – CommonsWare Jan 09 '15 at 13:38
  • you are on true, thanks a lot :) btw my apk is still with a huge size!! 3 megabytes :( – NullPointerException Jan 09 '15 at 15:38
  • 1
    The `play-services-ads` library is 380KB, and it depends upon `play-services-base`, which is 1.1MB. That in turn depends upon `support-v4`, which is another 860KB. Minification and resource shrinking are inexact sciences, and so I am not terribly shocked that your APK grew by a fair bit. You might consider adding `resConfigs` to your Gradle script, per Cyril Mottier's [blog post on APK size reduction](http://cyrilmottier.com/2014/08/26/putting-your-apks-on-diet/). Or, use a less pudgy ad network. :-) – CommonsWare Jan 09 '15 at 15:52

0 Answers0