Viral Patel
Viral Patel

Reputation: 33408

shrinkResources set to true, but all unused resources (specifically drawables) not getting removed

I'm setting shrinkResources to true as follows:

releasepro {
    minifyEnabled true
    shrinkResources true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    applicationIdSuffix ".pro"
}

But this is removing only a few unused resources. I am aware that gradle does some guessing and leaves resources that is is not sure are unused. Is there a way to remove all unused resources 100% ?

I read about setting the shrinkMode to strict in another thread. Will that help? I could not try it as I could not figure where to set it. Looked for examples and documents but unfortunately could not get to the right page.

Is there a way to ensure 100% removal of unused resources?

Upvotes: 14

Views: 17655

Answers (2)

Dilroop Singh
Dilroop Singh

Reputation: 544

R.raw.Keep (xml file)

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:shrinkMode="strict" />

Dont forget to Reference this Resource from .java source file. For more details see this

if you are worried about the size of your apk file then its good practice to shrink image files as well. That is convert RGB channel to Indexed channel,this can save up to 50% more space.

Use this site to Shrink your images media4x.com

Upvotes: 5

TheTool
TheTool

Reputation: 309

To turn off the safety checks, set the shrinkMode to "strict" as in the following keep.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:shrinkMode="strict" />

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

Upvotes: 1

Related Questions