小编aar*_*ino的帖子

APK按密度分割仍然包含所有资源

我决定尝试apk sliptting来减少我的apk的大小.我在gradle构建文件中添加了以下内容

splits {

    // Configures multiple APKs based on screen density.
    density {

        // Configures multiple APKs based on screen density.
        enable true

        // Specifies a list of screen densities Gradle should not create multiple APKs for.
        exclude "ldpi"

        // Specifies a list of compatible screen size settings for the manifest.
        compatibleScreens 'small', 'normal'
    }
}
Run Code Online (Sandbox Code Playgroud)

这成功地为各种密度生成单独的apks.但是,我注意到所有的apks都是相同的大小,没有一个比通用apk小.所以,我将一个(app-hdpi-release.apk)加载到apk分析器中,发现它包含所有资源.没有人被剥夺.

因此,所有配置都有效地生成了具有不同文件名的相同apk.我错过了什么吗?是否有任何其他构建选项可能会阻止正在删除的资源?

android gradle android-gradle-plugin

8
推荐指数
1
解决办法
417
查看次数

如何覆盖模块中的 gradle 子项目配置?

我的模块化 Android 项目subprojects在根 build.gradle 中使用,以最小化每个子模块的 build.gradle 中所需的配置。例如,我可以使用它来将我们的自定义 buildType 添加到每个模块

subprojects 
    afterEvaluate { project ->

        if (project.plugins.findPlugin('android') ?: project.plugins.findPlugin('android-library')) {
            android {
                buildTypes {
                    qa {
                        initWith debug
                        matchingFallbacks = ['debug']
                    }
                }
            }
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

我的假设是,如果我还将此构建配置添加到模块级别 build.gradle 中,它将覆盖项目级别定义的配置。然而,情况似乎并非如此。

如果我将以下内容添加到我的app / build.gradle时,我的应用程序将在选择qa buildtype时,请结束后缀'dev'。

buildTypes {
        debug {
            applicationIdSuffix = ".dev"
            signingConfig signingConfigs.debug
        }

        qa {
            initWith debug
            applicationIdSuffix = ".qa"
            matchingFallbacks = ['debug']
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }
Run Code Online (Sandbox Code Playgroud)

当我尝试在模块中使用特定于 buildType 的 buildConfigFields 时,同样的问题也适用;他们被忽略了。 …

android gradle android-gradle-plugin android-module

5
推荐指数
0
解决办法
457
查看次数