【发布时间】:2017-06-11 18:34:58
【问题描述】:
在我之前的所有项目中,调试版本总是更大,发布版本更小。
但是我遇到了奇怪的问题。 当我构建调试 APK 时,它有 1085KB
如果我构建发布版 APK,它有 2432KB
任何人都给我这个问题的解决方案。
我在 build.gradle 中的依赖项:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "ranjih.kotlinandroid"
minSdkVersion 14
targetSdkVersion 25
versionCode 5
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-config:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.google.android.gms:play-services-ads:10.2.1'
compile 'com.android.support:support-v4:25.3.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile project(path: ':lib')
}
apply plugin: 'com.google.gms.google-services'
repositories {
maven {
url "https://jitpack.io"
}
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// These docs use an open ended version so that our plugin
// can be updated quickly in response to Android tooling updates
// We recommend changing it to the latest version from our changelog:
// https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
classpath 'io.fabric.tools:gradle:1.+'
}
}
【问题讨论】:
-
你的应用中有很多图片资源吗? Android Studio 可能不会在调试版本中打包所有分辨率。
-
@Jonathan727 我没有很多图片。但是我在资产文件夹中有更多的 HTML 文件。我的疑问是应用程序兼容性依赖。这种依赖性会增加应用程序的大小吗?
-
我建议按照@Moonbloom 的建议进行测试,并生成两个发布版 APK,一个带压缩包,一个不带压缩包。
buildTypes { release { minifyEnabled false} releaseMinify { minifiyEnabled true } } -
另外,请为您的应用发布整个 build.gradle 文件
-
@Jonathan727 如果我给 { release { minifyEnabled false}} 它会生成 3764KB。但我不知道为什么调试构建需要更少的大小。添加了完整的 gradle 文件。
标签: android android-studio android-gradle-plugin