Unused images in android studio project are included in APK?

Asked

Viewed 95 times

3

Normally I’m not satisfied with the first image I put up as background, is from Activity, textView, button, etc. Even imageViews at last.

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

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

inserir a descrição da imagem aqui

It turns out that when I went to pass the apk to my physical android device, I found the size of the apk very large compared to the application which is quite simple actually. So I came up with the idea of analyzing the apk, so I realized that the images, even those that were not being used, were being accounted for in the weight of the apk:

inserir a descrição da imagem aqui

I honestly did not understand why they are included in apk. Engines of games like Unity for example, delete unused images and files from your executable and the application itself.

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

  • 1

    It should, but it is not. Face the apk is like a zip.

1 answer

6


Not if you set your app build.Gradle for that purpose.

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 time of build.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.