Minify android app but do not obfuscate it

Viewed 14708

When I do not minify my app I reach the maximum method count and building the dex file fails. This can be avoided by enabling minify in build.gradle. The downside, however, is that now the code gets obfuscated. This is OK for the Release build but it is problematic for a Debug build.

Is there a way to tell gradle to minify a Debug build but not obfuscate it?

4 Answers
minifyEnabled true

is just a shortcut for:

postprocessing {
    removeUnusedCode true
    obfuscate true
    optimizeCode true
}

So, if you want to minify without obfuscating, replace minifyEnabled true with:

postprocessing {
    removeUnusedCode true
    obfuscate false // <--
    optimizeCode true
}

Additionally, the compiler will complain if you have shrinkResources true. The equivalent postprocessing field is removeUnusedResources true, i.e:

postprocessing {
    removeUnusedCode true
    removeUnusedResources true // <--
    obfuscate false
    optimizeCode true
}

Contrary to other answers, useProguard false does not disable obfuscation; it changes the obfuscation engine from ProGuard to R8.

Related