Home » Android » android release apk bigger than debug apk

android release apk bigger than debug apk

Posted by: admin May 14, 2020 Leave a comment

Questions:

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'
}
}

and

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

    dependencies {
        ...
    }

enter image description here

enter image description here

How to&Answers:

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).

Answer:

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 😉