代码之家  ›  专栏  ›  技术社区  ›  Alexander Farber

屏幕密度的多个APK仍然包括所有资源,APK文件大小保持不变

  •  0
  • Alexander Farber  · 技术社区  · 7 年前

    我的游戏应用程序包括4个代表不同游戏板的大型PNG图像:

    android studio screenshot

    为了减少APK文件的大小,我遵循了 Build Multiple APKs 文档,并将以下部分添加到 应用程序/内部版本。格拉德尔 文件:

    splits {
        density {
            enable true
            reset()
            include "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
        }
    }
    

    之后,我选择 构建->生成已签名的APK。。。 在Android Studio菜单中。

    令人惊讶的是,APK文件仍然具有相同的文件大小:

    APK files

    分析APK。。。 显示的资源 全部的 屏幕密度仍包括在内:

    analyze screenshot

    请问我在这里遗漏了什么,如何排除不必要的资源?

    我的整个 应用程序/内部版本。格拉德尔 如下所示:

    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'
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Alexander Farber    7 年前

    我的答案是 /r/androiddev -APK拆分仅适用于 可抽出式 ,但不适用于 纹理映射 目录。

    移动PNG文件后,APK文件大小减小:

    APK analyze

    为了批量移动所有资源,我在Terminal中使用了以下shell命令:

    对于f英寸/app/src/main/res/mipmap-{mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi}/game\u board\u*。巴布亚新几内亚;do echo git mv-v“$f”“${f/mipmap/drawable}”;完成

    (删除“echo”以运行实际命令)。