Remove unused resources using Android Studio?

In android studio. You can use Android Lint. It will show " Strings, Resource, import.." not use

Analyze -> Inspect Code -> Whole Project -> OK

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

enter image description here

Check the box prior confirm action so that you can get rid of unused @id declarations too.

  • In terms of APK optimization consider Selecting a Format fact as well.
  • Use WebP Images provide better compression than either JPEG or PNG. Lossy WebP images are supported in Android 4.0 (API level 14) and higher, and lossless and transparent WebP images are supported in Android 4.3 (API level 18) and higher.