Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 686
AndroidMechanic - Viral Patel Avatar asked Dec 17 '15 14:12

AndroidMechanic - Viral Patel


People also ask

How to enable resource shrinking in ProGuard?

To enable resource shrinking, set the shrinkResources property to true in your build.gradle file. android { ... buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile ('proguard-android.txt'), 'proguard-rules.pro' } } }

What happens when I shrink resources in the build window?

When you shrink resources, the Build window shows a summary of the resources that are removed from the app. (You need to first click Toggle view on the left side of the window to display detailed text output from Gradle.) For example:

How do I remove unused resources in Android Studio?

And, as with code shrinking, removing unused resources is not automatic, but it is relatively easy to do. For your own project resources, you can remove them manually. Choose “Refactor” > “Remove Unused Resources” from the Android Studio main menu.

How do I enable shrinking and obfuscation in Android Gradle?

To enable shrinking, obfuscation, and optimization, include the following in your project-level build.gradle file. // your project's release build type. // Android Gradle plugin. // the Android Gradle plugin. To learn more, go to the section about // R8 configuration files. ...


1 Answers

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

like image 76
Dilroop Singh Avatar answered Nov 07 '22 09:11

Dilroop Singh