How to use R8 shrinking in the app?
Implementation of R8 shrinking is a single-step process. First of all, create a New Project with an empty activity inside Android Studio. For creating a new project in Android Studio. Take a look over this link on How to create a new project in Android Studio. After creating this new project. Navigate to the Gradle scripts > build.gradle(:app) and you will get to see the section of buildTypes. Inside this change minifyEnabled from false to true to enable R8. Below is the section where we have to make a change.
buildTypes {
release {
// make change here
minifyEnabled true
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
}
}
After changing it true sync your project and R8 is being added inside your application You can now test the APK size by building the APK. You can also test the APK size by adding some external libraries. Test the APK size using R8 and without using R8 you will get to see the difference between the size of APK.
How to use R8 to Reduce APK Size in Android?
If you are building any apps and you want to target this app to a large audience then there are so many factors which you should consider while building your apps. The most important factor while building any application is its size. The size of the app matters a lot. If your app size is very high then users don’t like to download such big apps that require such a huge storage space and data charges. So it is very important to maintain your app size for your users while building any Android application. In this article, we will take a look at reducing app size using R8.
Below are some of the topics which we will look at in this article
- What is R8?
- How to use R8 shrinking in your app?
- How the shrinking in R8 works?
The configuration required for using the R8 app shrinking
- For enabling R8 in your application you have to use the Android Studio version like 3.4 or higher.
- The Gradle version inside your project should have a version of around 3.4.0