【发布时间】:2018-01-06 08:53:17
【问题描述】:
我的游戏应用包含 4 个代表不同游戏板的大型 PNG 图像:
为了减少 APK 文件的大小,我遵循了 Build Multiple APKs 文档并将以下部分添加到 app/build.gradle 文件中:
splits {
density {
enable true
reset()
include "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
}
}
之后,我在 Android Studio 菜单中选择 Build -> Generate Signed APK...。
令人惊讶的是,APK 文件仍然具有相同的文件大小:
并且Analyze APK...显示仍然包含所有屏幕密度的资源:
请问我在这里遗漏了什么,如何排除不需要的资源?
我的整个 app/build.gradle 如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
resConfigs "en"
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
splits {
density {
enable true
reset()
include "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
}
}
}
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:$supportLibVersion"
compile "com.android.support:cardview-v7:$supportLibVersion"
compile "com.android.support:customtabs:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.google.android.gms:play-services-auth:$firebaseLibVersion"
compile "com.google.firebase:firebase-messaging:$firebaseLibVersion"
compile 'com.android.billingclient:billing:1.0'
compile 'com.github.bumptech.glide:glide:4.3.1'
compile 'com.neovisionaries:nv-websocket-client:2.3'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.28.0'
testCompile 'junit:junit:4.12'
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
标签: android android-studio android-gradle-plugin apk android-studio-3.0