Images not used in the android studio project are included in APK?

3

I'm usually not satisfied with the first image I put as background , be it activity, textView , button , etc. Even imageViews anyway.

It happens that I leave them there in the project, not even using them, with the thought that at some point I may need them, either for a test or even a comparison.

These are all "drawable" images of a project of mine:

ItturnsoutthatwhenIwenttopasstheapktomyphysicalandroiddevice,Ifoundtheapksizeverylargecomparedtotheapplicationthatisprettysimpleactually.SoIcameupwiththeideaofparsingapk,soIrealizedthattheimages,eventhosethatwerenotbeingused,werebeingcountedintheweightofapk:

I honestly did not understand why they are included in apk. Engines such as unity , for example, exclude unused images and files from your executable and the application itself.

I would like to know the explanation for this, since for me there is no sense, I should only count in apk what is used.

    
asked by anonymous 11.02.2017 / 20:21

1 answer

6

Do not set up your app build.gradle for this purpose.

For this, you should use the properties minifyEnabled and shrinkResources and "set them" with true :

android {
    ...
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}

Do this only in the final build, before creating the APK for distribution, as this increases the build time.

For more information, see Shrink Your Resources in the documentation.

    
11.02.2017 / 21:06