2

My main goal is to remove unused assets and libraries from the apk so that I can reduce it's size. I found Resource Shrinking while I was browsing through this SO post.

So I changed my gradle file to this:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId 'com.galleri5.android'
        multiDexEnabled true
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 12
        versionName "0.10"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

And to check whether this was working, I generated the apk and the size of the apk was same as before, no shrinking. So I tried to see if/which resources are being removed by running this command:

./gradlew clean assembleDebug --info | grep "Skipped unused resource"

And this is the output that I am getting:

Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar

I don't see and resources that are getting removed. Is there something I have done wrong or am I totally misunderstanding this tool? Any help would be highly appreciated. Thanks.

Edit I am just checking the size of the apk(apk-debug.apk) generated after running the app with above configuration. Does shrinking happen when I generate signed apk or would it be visible in the normal apk too?

Community
  • 1
  • 1
Amit Tiwari
  • 3,684
  • 6
  • 33
  • 75

1 Answers1

3

Resource shrinking will only occur in your release builds, as that's what you've specified in your build.gradle. You could add the following closure to buildTypes if you want to minify in your debug builds, generally this isn't done.

buildTypes {
    debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
fractalwrench
  • 4,028
  • 7
  • 33
  • 49