Android Studio 3.0风味尺寸问题


224

升级到Studio Canary版本。我之前的Telegram Messenger项目中出现以下错误。

错误:所有风味现在必须属于命名的风味维度。没有将风味“ armv7”分配给风味尺寸。进一步了解https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

我该怎么办?我已经看过该链接,但不知道该怎么办。我现在有3个构建变体,即release,debug和foss。

Answers:


528

如果您确实不需要该机制,则只需在您的中指定一个随机的风味尺寸即可build.gradle

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

有关更多信息,请参阅迁移指南


1
谢谢。我已经有一个维度“ versionCode”,我已经使用过了。
Omkar Nath Singh's

2
flavourDimensions“ versionCode” productFlavors {调试{维度“ default” versionName“ 1.0”}版本{维度“ default” versionName“ 1.0”} foss {维度“ default” versionName“ 1.0”}}我收到此错误..ProductFlavor名称无法冲突带有BuildType名称。能否请任何人帮助我。我在Kotlin上收到了AS 3.0 beta版Canary的错误消息。
Md Maidul Islam

5
如果只有一个维度,则无需在每种口味中都指定它。只需flavorDimensions "default"上面的第一行。
格雷厄姆·博兰

1
@GrahamBorland感谢您的提示,我相应地更新了答案。
tknell

1
也许加上,该文件是app/build.gradle
spedy

60

经过仔细阅读后,我自己解决了。解决方案是在build.gradle中添加以下行。

flavourDimensions“ versionCode”

android { 
       compileSdkVersion 24
       .....
       flavorDimensions "versionCode"
} 

2
您在gradle中的哪一行添加了此行?多一点内容会有所帮助
Brando Madden

2
在Android {...}内部的build.gradle文件中
Omkar Nath Singh

android {compileSdkVersion 24 .... //在这里添加}
Omkar Nath Singh

16
为什么使用“ versionCode”而不是其他任何内容?它会影响versionCode吗?
MBH

1
@MBH我的productFlavours中有这个。您只需要任何唯一的密钥即可识别。
奥卡·纳斯·辛格

40

在这里您可以解决此问题,您需要添加带有productFlavors名称的flavourDimension,还需要定义尺寸,请参见以下示例,有关更多信息,请参见 https://developer.android.com/studio/build/gradle-plugin- 3-0-0-migration.html

flavorDimensions 'yourAppName' //here defined dimensions
productFlavors {
    production {
        dimension 'yourAppName' //you just need to add this line
        //here you no need to write applicationIdSuffix because by default it will point to your app package which is also available inside manifest.xml file.

    }

    staging {
        dimension 'yourAppName' //added here also
        applicationIdSuffix ".staging"//(.staging) will be added after your default package name.
        //or you can also use applicationId="your_package_name.staging" instead of applicationIdSuffix but remember if you are using applicationId then You have to mention full package name.
        //versionNameSuffix "-staging"

    }

    develop {
        dimension 'yourAppName' //add here too
        applicationIdSuffix ".develop"
        //versionNameSuffix "-develop"

    }

19

如果您不想使用尺寸,则应使用此行

android { 
compileSdkVersion 24

...
flavorDimensions "default"
...
}

但是,如果要使用尺寸,则应首先声明尺寸名称,然后在此示例来自文档后使用该名称:

android {
...
buildTypes {
debug {...}
release {...}
}

  // Specifies the flavor dimensions you want to use. The order in which you
  // list each dimension determines its priority, from highest to lowest,
  // when Gradle merges variant sources and configurations. You must assign
  // each product flavor you configure to one of the flavor dimensions.
  flavorDimensions "api", "mode"

  productFlavors {
    demo {
  // Assigns this product flavor to the "mode" flavor dimension.
  dimension "mode"
  ...
}

full {
  dimension "mode"
  ...
}

// Configurations in the "api" product flavors override those in "mode"
// flavors and the defaultConfig block. Gradle determines the priority
// between flavor dimensions based on the order in which they appear next
// to the flavorDimensions property above--the first dimension has a higher
// priority than the second, and so on.
minApi24 {
  dimension "api"
  minSdkVersion 24
  // To ensure the target device receives the version of the app with
  // the highest compatible API level, assign version codes in increasing
  // value with API level. To learn more about assigning version codes to
  // support app updates and uploading to Google Play, read Multiple APK Support
  versionCode 30000 + android.defaultConfig.versionCode
  versionNameSuffix "-minApi24"
  ...
}

minApi23 {
  dimension "api"
  minSdkVersion 23
  versionCode 20000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi23"
  ...
}

minApi21 {
  dimension "api"
  minSdkVersion 21
  versionCode 10000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi21"
  ...
    }
  }
}
...

9

我在build.gradle中为我的应用程序使用了flavorDimensions(模块:app)

flavorDimensions "tier"

productFlavors {
    production {
        flavorDimensions "tier"
        //manifestPlaceholders = [appName: APP_NAME]
        //signingConfig signingConfigs.config
    }
    staging {
        flavorDimensions "tier"
        //manifestPlaceholders = [appName: APP_NAME_STAGING]
        //applicationIdSuffix ".staging"
        //versionNameSuffix "-staging"
        //signingConfig signingConfigs.config
    }
}

检查此链接以获取更多信息

// Specifies two flavor dimensions.
flavorDimensions "tier", "minApi"

productFlavors {
     free {
            // Assigns this product flavor to the "tier" flavor dimension. Specifying
            // this property is optional if you are using only one dimension.
            dimension "tier"
            ...
     }

     paid {
            dimension "tier"
            ...
     }

     minApi23 {
            dimension "minApi"
            ...
     }

     minApi18 {
            dimension "minApi"
            ...
     }
}

0

如果您具有简单的风格(免费/专业版,演示/完整版等),请添加到build.gradle文件中:

android {
...
flavorDimensions "version"
productFlavors {
        free{
            dimension "version"
            ...
            }
        pro{
            dimension "version"
            ...
            }
}

通过尺寸,您可以创建“风味中的风味”。阅读更多

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.