android发布apk比调试apk大 [英] android release apk bigger than debug apk

查看:34
本文介绍了android发布apk比调试apk大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 proguard 来减小我的 apk 大小.调试 apk 从 90mb 减少到 55mb,但签名 apk 是 71mb.这是我的 build.gradle 代码:

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 {
        ...
    }

推荐答案

进一步解释sosite的回答,看来这个仅当比较通过 Run 或 Debug 构建的用于特定设备(即使没有启用 Instant Run)的 debug apk 而不是通过 Build > Build APK 构建的 debug apk(适用于任何支持的设备).

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

通过 Build APK 构建的任何变体(甚至 debug 本身)都将包含该变体的所有资源.此外,Run/Debug apk 包含特定于该单个设备的预dexed 类,而Build APK 仅包含一些编译器认为安全的通用预dexed 类所有支持的设备 - 完整的 dexing 仅在安装 apk 时发生在设备本身中.

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.

我已经将一个通过 Debug 生成的 apk 与另一个通过 Build APK 生成的 apk 压缩,用于同一项目的相同变体和 发布了简化的输出用于演示(也可作为 html 使用).

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

这篇关于android发布apk比调试apk大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆