6

如何解决以下警告?有没有“汽车”的替代品?

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

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

2 回答 2

8

这是更新到 Android Studio 3.1 后的错误:

在此处输入图像描述

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

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"(仅限 1 种语言)调试 APK 为:3,294 KB

这意味着对于这些依赖项的所有语言的所有字符串资源,我只得到了大约 500KB 的大小增加。这是您可以推理的事情,您绝对应该使用您使用的依赖项进行测试,看看大小增加是否可以忽略不计,然后决定提供支持的语言列表或删除resConfigs选项。

PS:如果您使用的是 Android FirebaseUI,这是建议的优化之一,我在这里创建了一个关于这件事的问题,这已经被一个很棒的家伙立即解决了SUPERCILEX

于 2018-03-26T21:47:02.733 回答
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.
于 2018-03-26T18:48:26.430 回答