Android Studio 3.0 Flavor Dimension问题

时间:2017-05-22 05:19:32

标签: android android-studio gradle armv7

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

  

错误:所有风格现在必须属于命名风味维度。风味' armv7'未分配给风味维度。请访问https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

了解详情

我该怎么办?我已经看过这个链接,但无法理解该怎么做。我现在有3个构建变体,发布,调试和foss。

7 个答案:

答案 0 :(得分:484)

如果您真的不需要这种机制,只需在build.gradle中指定随机风味维度:

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

有关详细信息,请查看migration guide

答案 1 :(得分:58)

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

  

flavorDimensions" versionCode"

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

答案 2 :(得分:34)

在这里您可以解决此问题,您需要添加带有productFlavors名称的flavorDimension,并且还需要定义维度,请参阅下面的示例,有关详细信息,请参阅此处 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

flavorDimensions 'free','paid' //here defined dimensions
productFlavors {
    production {
        dimension 'paid' //you just need to add this line
        ... // your existing code

    }

    demo {
        dimension 'free' //added here also
        ... // your existing code

    }

    development {
        dimension 'free' //add here too
        ... // your existing code

    }

答案 3 :(得分:17)

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

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"
  ...
    }
  }
}
...

答案 4 :(得分:8)

我在build.gradle(Module:app)

中使用了flavorDimensions作为我的应用程序
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
    }
}

Check this link for more info

// 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"
            ...
     }
}

答案 5 :(得分:1)

在KotlinDSL中,您可以这样使用:

flavorDimensions ("PlaceApp")
productFlavors {
    create("tapsi") {
        setDimension("PlaceApp")
        buildConfigField("String", "API_BASE_URL", "https://xxx/x/x/")
    }

}

答案 6 :(得分:0)

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

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

按维度,您可以创建“风味中的风味”。 Read more