I am preparing to release an App to production. So, I generated signed apk. After generating signed apk, I was getting a problem. My apk file size is a little large and I tried ways to shrink the apk size. I already tried
app --> Refactor --> Remove Unused Resources
and it is not too reduce. So, I added shrinkResources true in my build.gradle(app)
buildTypes { release { minifyEnabled false shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
After adding shrinkResources true and I got below error when I rebuild. My question is how should I turn on unused Code shrinking first? Thanks and appreciating.
Code shrinking helps reduce the size of your APK by getting rid of unused code and resources as well as making your actual code take less space (also known as minification or obfuscation).
The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized . apk file that is more difficult to reverse engineer. You can easily search for unused resources from Android Studio.
Shrink your code. Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true . Code shrinking (also known as tree shaking), is the process of removing code that R8 determines is not required at runtime.
Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. This is especially true when you add code libraries that include resources—you must remove unused library code so the library resources become unreferenced and, thus, removable by the resource shrinker
To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking). For example:
android { ... buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With