ERROR: All flavors must now belong to a named flavor dimension

ERROR: All flavors must now belong to a named flavor dimension

Screenshot from Android my build.gradle

第一次接触风味维度。我正在尝试编译现成的代码,但不知何故我遇到了这个问题。

错误:

All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html Affected Modules: app

抱歉我是菜鸟,真的不知道怎么解决。如果有人有解决方案,请帮助我。

如何解决这个问题?

来自Android documentation

All flavors must belong to a named flavor dimension, which is a group of product flavors. You must assign all flavors to a flavor dimension; otherwise, you will get the build error shown below. If a given module specifies only one flavor dimension, the Android Gradle plugin automatically assigns all of the module's flavors to that dimension.

因此,如果您不关心有不同的风味维度命名,您可以在 module 中指定一个,它将应用于所有 flavors,如下所示。

android { 
    ...
    flavorDimensions "default"
    ...
}

如果您关心不同的命名方式,您可以采用这种方法:

android {
...
flavorDimensions "default"
...
}


 productFlavors {
            inmemory {
                ...
                dimension "DIM_NAME"
            }
            live {
                ...
                dimension "DIM_NAME_2"
            }
        }