"ProductFlavor.resConfigs"的值为"auto",已经过时且未被替换。

6

如何修复以下警告?是否有“auto”以外的替代方法?

警告:DSL元素“ProductFlavor.resConfigs”的值为“auto”,已过时且未被替换。 它将在2018年底被删除。

android {
    ...
    flavorDimensions "device", "paid", "market"
    productFlavors {
        phone {
            // Phone config version for the application
            resConfigs ("auto")
            dimension "device"
            matchingFallbacks = ['mobile']
        }
        ...     
    }
    ...
}
2个回答

8
这是在升级至Android Studio 3.1后出现的错误:

enter image description here

根据官方建议这里,如果您支持所有语言,则最好的做法是完全删除标签,或者提供一个包含您的应用程序支持的语言代码的数组,例如:

resConfigs "en", "de", "it", "fr" // etc. etc.

更多信息:

这是官方文档此处提出的资源优化之一,因此我决定在一个样例项目中测试这个标记与那些FirebaseUI依赖关系。

implementation "com.firebaseui:firebase-ui-auth:$firebase_ui_version"
implementation "com.firebaseui:firebase-ui-database:$firebase_ui_version"
implementation "com.firebaseui:firebase-ui-storage:$firebase_ui_version"

使用这两种选项创建调试APK,以下是结果:

  • 使用resConfigs "auto",调试APK大小为:3,793 KB
  • 使用resConfigs "en"(只有一种语言),调试APK大小为:3,294 KB

这意味着对于那些依赖的所有语言的字符串资源,我仅增加了约500KB的大小。你可以思考一下这个问题,通过测试使用的依赖项,看看大小增加是否可以忽略不计,然后决定提供支持的语言列表或删除resConfigs选项。

PS:如果你正在使用Android FirebaseUI,这是其中一个建议的优化方法,我已经在这里创建了一个问题,并由名为SUPERCILEX的了不起的人立即解决了这个问题。


1
"auto"不再受支持,因为它在多模块项目中会产生许多问题。相反,您应该指定应用程序支持的语言环境。Android插件3.1.0及更高版本忽略auto参数,并且Gradle将打包所有字符串资源,包括应用程序和其依赖项提供的资源。 com.android.tools.build:gradle:3.2.0-alpha08 BaseFlavor.java
 * <p><b>Note:</b> <code>auto</code> is no longer supported because it created a number of
 * issues with multi-module projects. Instead, you should specify the locale that your app
 * supports, as shown in the sample above. Android plugin 3.1.0 and higher ignore the <code>auto
 * </code> argument, and Gradle packages all string resources your app and its dependencies
 * provide.

你提到“它在多模块项目中创建了许多问题”。我知道官方文档上是这么说的,但你知道在哪里可以找到更多关于这些问题的具体信息吗?例如,我一直在试图找到使auto成为无操作的提交,但一直没有找到(甚至3.1.0插件的源代码是否已经发布?)。 - Aaron
1
@Aaron 抱歉,我不知道你可以在哪里找到更多有关问题的特定信息。 3.1.0插件的来源 - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom - Alexander Savin
谢谢,但不幸的是,pom文件只链接到https://android.googlesource.com/platform/tools/base,我无法找到3.0.0之后的源代码。 - Aaron
1
@Aaron https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0-sources.jar https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.1.0/gradle-core-3.1.0-sources.jar 等。 - Alexander Savin
谢谢,我简直不敢相信我竟然忽略了源jar包。此外,Google现在已经发布了3.1.2的git历史记录,我成功找到了我要找的提交(尽管它仍然不能真正解释问题):https://android.googlesource.com/platform/tools/base/+/6b7799c36f1ba5194f73f5c14a7b0365a8428714%5E%21/ - Aaron

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接