Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing unused resources requires unused code shrinking to be turned on

Tags:

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.

enter image description here

like image 261
ZarNi Myo Sett Win Avatar asked Sep 13 '18 09:09

ZarNi Myo Sett Win


People also ask

What is use code shrinking?

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).

Does ProGuard remove unused resources?

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.

How to shrink code in 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.


1 Answers

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

like image 84
Mostafa Anter Avatar answered Sep 17 '22 12:09

Mostafa Anter