I want to remove unused resources from my project to reduce the app size. Is there any way to do it by using Android Studio IDE efficiently?
Check File mask(s) checkbox and put strings. xml in the text field. Then you can define Custom scope , choosing Production classes -> app -> values to find unused strings, colors ...
It will help you not only to remove unused resources, but also to find potential bugs. The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.
The Gradle build system for Android supports Resource Shrinking :
the automatic removal of resources that are unused, at build time, in the packaged app. In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application.
For example, your application is using Google Play Services to for example access Google Drive functionality, and you are not currently using Google Sign In, then this would remove the various drawable assets for the Sign In buttons.
Note: Resource Shrinking only works in conjunction with code shrinking (such as ProGuard). That's how it can remove unused resources from libraries; normally, all resources in a library are used, and it is only when we remove unused code that it becomes apparent which resources are referenced from the remaining code.
To enable resource shrinking, update your build type as follows:
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
And google recently launched Android Studio 2.0 officially, Now they are giving an option in the IDE itself.
Right click on app --> Refactor --> Remove Unused Resources
It will prompt
Check the box prior confirm action so that you can get rid of unused @id
declarations too.
In android studio. You can use Android Lint. It will show " Strings, Resource, import.." not use
Analyze -> Inspect Code -> Whole Project -> OK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With