Code obfuscation

The next step in the release process is to enable code obfuscation. Open your build.gradle configuration and update it as follows:

    ... 
    buildTypes { 
      ... 
      release { 
        debuggable false 
        minifyEnabled true 
        proguardFiles getDefaultProguardFile('proguard-android.txt'),         'proguard-rules.pro' 
      } 
    } 
    ... 

The configuration we just added will shrink resources and perform obfuscation. For the obfuscation, we will use ProGuard. ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It performs detection of unused classes, fields, methods, and attributes. It optimizes bytecode as well!

In most cases, the default ProGuard configuration (the one we use) is enough to remove all the unused code. However, it can happen ...

Get Mastering Android Development with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.