Does Android Studio remove resources that the app does not use or leave them even if they are not used?

2

I have a question: if I have in my project in Android Studio resources that the application itself does not use (for example, some pictures that are not used in the app) but these are stored in the / drawable folder, when I compile the apk, does Android studio delete those photos or just leave them in the compiled apk occupying space even if they are not used?

    
asked by Felix A Marrero Pentón 14.02.2017 в 15:31
source

3 answers

1

It depends on how you have defined it in the Gradle, to be more exact of the properties minifyEnabled and shrinkResources. Documentation.

  

What exactly does "minifyEnabled" and "shrinkResources" mean?

minifycorre shrinks only code and shrinkeliminar removes resources marked as unused from the res folder. ProGuard is the one that really analyzes the code to know what is not used.

Eye .. shrinkResourcesse is taken into account only if minifyEnabledes is true

  

Do any of these options affect the size and / or quality of the image files?

No!

    
answered by 14.02.2017 в 15:55
0

That depends on the configuration in your build.gradle

This eliminates what is not needed:

buildTypes {
    release {
        minifyEnabled true

and so not:

buildTypes {
    debug {
        minifyEnabled false
    
answered by 14.02.2017 в 15:57
0
  

Does Android Studio remove resources that the app does not use or leave them?   even if they are not used?

The answer is not to delete them, by default the resources remain in the generated .apk.

to remove resources easily go to the option menu:

  

Refactor > Remove Unused resources

With this option the resources that are not used in your project will be removed easily and you will not have to be looking at the project.

The shrinkResources and minifyEnabled properties do not actually remove resources not used by the application.

  

shrinkResources merge resources with similar names that in   Sometimes we can leave in different resource directories.

     

minifyEnabled for code reduction and optimization.

this can be configured within the file: build.gradle

android {
    ...
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}
    
answered by 14.02.2017 в 16:10