What is Proguard?
Proguard is a java tool in Android that helps to do the following things such as:
- It removes the unused classes and methods from your app which helps to reduce the size of your APK.
- It makes your application difficult to reverse engineer by obfuscating the code.
- It reduces the size of your application.
How to enable Proguard in your Application?
To enable proguard in your application Navigate to the Gradle Scripts > build.gradle(:app) and then you will get to see a method called buildTypes.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
}
}
In this block of code, we have to change minifyEnabled to true to activate our Proguard. This code of Proguard is written under the release block so it will only work on the release build of your APK. It will activate the proguard which will take it from the file named as
‘proguard-android.txt’.
Difference Between Proguard and R8 in Android
Proguard and R8 both are similar tools that are used for reducing the size of our APK and increase the performance of our APK by shrinking the unused resources. In this article, we will take a look at:
- What is Proguard?
- What is R8?
- Difference between Proguard and R8.