What is Proguard ?
Proguard is free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names.
1. Shrinking – detects and removes unused classes, fields, methods, and attributes.
2. Optimization – analyzes and optimizes the bytecode of the methods.
3. Obfuscation – renames the remaining classes, fields, and methods using short meaningless names.
Why Proguard for Android?
Android Applications are quite easy to reverse engineer, so if you want to prevent this from happening, you should use Proguard for its main function: Obfuscation. The other two important functions of Proguard are Shrinking and Optimization. Shrinking eliminates unused codes and it is highly useful. Optimization operates with java bytecode, though, since Android runs on special bytecode which is converted from java bytecode some optimizations won’t work well.
Proguard obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names which make the code base, smaller and more efficient. The result is a smaller sized .apk file that is more difficult to reverse engineer.
How to Enable Proguard in Android Studio?
1. Proguard is integrated into the Android build system.
2. Proguard runs only when you build your application in release mode.
3. Having Proguard run is completely optional, but highly recommended.
4. In Android Studio project, the minifyEnabled property in the build. gradle file enables and disables Proguard for release builds.
5. The minifyEnabled property is part of the buildTypes release block that controls the settings applied to release builds.
6. Set the minifyEnabled property to true to enable Proguard.
7. The getDefaultProguardFile(‘proguard-android.txt’) method obtains the default Proguard settings from the Android SDK tools/proguard folder.
8. Android Studio adds the proguard-rules.pro file at the root of the module, which helps to add custom Proguard rules.
1. Potential misconfiguration causes the app to get crash.
2. Additional testing is required
3. Stacktraces are difficult to read with obfuscated method names.
4. ClassNotFoundExceptions, which happens when Proguard strips away an entire class that application calls.
We can fix ClassNotFoundExceptions by adding a -keep line in Proguard configuration file.
-keep public class
Happy Coding !
We are Perfomatix. We specialize in building highly scalable APIs and Mobile apps and we also have strong expertise in IoT apps, Virtual Reality apps, and Augmented Reality apps. Get in touch with us to find out how we can help in shaping your disruptive idea into a prototype, MVP and finally into a killer product. Visit our success stories section to find out more about some of the startups which made it big with us.