I have used the lint(Analyze->Inspect Code...) and find out unused methods and resources. All the unused resources removed by Refractor->Remove unused R
Android ships with ProGuard and can do what you want. If you are using Gradle as build system then you can add the following lines in your build.gradle
file:
android {
// ... other configurations
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules-debug.pro'
}
}
}
Your proguard-rules-debug.pro
file only needs to contain one line
-dontobfuscate
With this additions your release build will get shrunk and obfuscated, your debug build, however, will get only shrunk, i.e, unnecessary code is removed. Note, that ProGuard operates on the build and not the source code.
The ProGuard FAQ has some more information of what it can do.