Reducing android app (apk) size

前端 未结 16 1442
借酒劲吻你
借酒劲吻你 2020-11-29 20:51

I would be now publishing my first app on Google play store. I have already compressed images used in my app. And I have some questions regarding the app size.

16条回答
  •  星月不相逢
    2020-11-29 21:06

    Generally, in ProGuard, you can use the following to shrink your APK (this is in your module's build.gradle file):

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

    Specifically, look at minifyEnabled true and shrinkResources true:

    minifyEnabled is responsible for obfuscating and shrinking your code files (e.g. Java). It is the main feature of ProGuard, and helps to shrink your APK as well as making it difficult to reverse engineer.

    shrinkResources is used to remove unused resource files (such as images and other assets). For example, if you are compiling with an Android library, but you are not using some images in that Android library, they will not be included in the final build. There is a good Android Developers video about it here.

提交回复
热议问题