gpt4 book ai didi

Android Gradle 2.2 不允许签名 APK 的 ShrinkResources

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:24 24 4
gpt4 key购买 nike

作为 Android Studio 2.2 推出的一部分,我将我的 Gradle 构建工具更新到了 v2.2。这样做之后,我签名的 APK 构建过程失败了,因为我有 shrinkResources = true。

一旦我切换回 Gradle v2.1.3 或设置 shrinkResources = false 一切正常。这是我的应用程序 gradle 构建文件:

    android {
signingConfigs {

}
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
applicationId "com.sample.testapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 4
versionName "0.0.4"
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'C:/Users/code/testapp/app/proguard-rules.pro'
}
}
productFlavors {
}
}

当 Gradle 设置为 v2.2 时,这是我在生成签名 APK 时遇到的构建错误

enter image description here

有谁知道为什么会发生这种情况以及是否有解决方法?我在 Google 上搜索了一下,看到了一些关于 alpha 和 beta Gradle 构建有这个问题的较旧的 Android Bug 报告,但我发现的报告是 >6 个月前的(以及以前的 Gradle 版本)。

附言我知道 minifyEnabled = false 目前,我还没有调查我包含的库的正确混淆规则集,以防止签名构建由于缺少库而出错。

最佳答案

要使用shr​​inkResources,您必须使用minifyEnabled

根据 Android documentation :

Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. This is especially true when you add code libraries that include resources—you must remove unused library code so the library resources become unreferenced and, thus, removable by the resource shrinker.

To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking).

关于Android Gradle 2.2 不允许签名 APK 的 ShrinkResources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39628648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com