android release apk bigger than debug apk

醉酒当歌 提交于 2019-12-04 00:15:36

问题


I'm using proguard to reduce my apk size. The debug apk reduce from 90mb to 55mb, but the signed apk is 71mb. Here is my build.gradle code:

apply plugin: 'com.android.application'

android {

signingConfigs {
    XXXX {
        keyAlias 'xxxx'
        keyPassword 'xxxx'
        storeFile file('/Users/xxxx.jks')
        storePassword 'xxxxxx'
    }
}
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
    applicationId "com.xxxx"
    minSdkVersion 14
    targetSdkVersion 22
    versionCode 61
    versionName "4.1.8.1"
    multiDexEnabled true
    signingConfig signingConfigs.XXXX

    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
    }
}

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

dexOptions {
    javaMaxHeapSize "4g"
}

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
}

}

repositories { mavenLocal() maven { name "jcenter" url "http://jcenter.bintray.com/" } }

dependencies { ... }


回答1:


Further explaining sosite's answer, it seems that this happens only if comparing a debug apk built via Run or Debug meant for a specific device (even without Instant Run enabled) instead of a debugapk built via Build > Build APK (for any supported device).

Any variant (even debug itself) built via Build APK will include all the resources for that variant. Also, the Run/Debug apk includes pre-dexed classes specific for that single device, while Build APK ones includes only some general pre-dexed classes that the compiler determines safe for all supported devices - the full dexing only occurs in the device itself, when the apk is installed.

I've zipdiff-ed an apk generated via Debug with another via Build APK for the same variant of the same project and published the simplified output for demonstration (also available as html).




回答2:


When you build your app locally for specific type of phone then Android Studio attach only necessary resource files. When you build release version then you have attached all types of drawables so you app file size can increase drastically.

I suggest you to use jpg in place of png in as many places as you can and compress them of course - often I use tinyPNG website or just Photoshop ;)



来源:https://stackoverflow.com/questions/39636182/android-release-apk-bigger-than-debug-apk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!