how Android source code minify and obfuscate?

Enable shrinkResources in your build type. Note that it requires minify to be enabled. In your Gradle file:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}

The accepted answer is now outdated, so I added this answer if someone else stumbles upon this question.


You can use ProGuard for this. Note however that your code will be obfuscated when it comes to crash reports etc so you need to keep obfuscation maps to be able to retrieve the stack traces between versions etc. It does however protect you a lot better from reverse engineering your .APK.

More info@Android Developers: http://developer.android.com/tools/help/proguard.html


There are three part

  1. minifyEnabled
  2. useProguard
  3. shrinkResources

if you want to remove unused part of coding then you can use shrinkResources true

if you don't want to use default files like dmp.txt,mapping.txt,seeds.txt,usage.txt etc then you should use useProguard false

if you want to shrink your code and resource then you have to use minifyEnabled true

for more details refer this link