Error:All flavors must now belong to a named flavor dimension. The flavor 'flavor_name' is ...

android studio 3.0,更新html

classpath ‘com.android.tools.build:gradle:3.0.0’之後,出現報錯android

Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.

報錯的緣由:查看給出的連接地址:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#apply_pluginapp

The plugin now requires that all flavors belong to a named flavor dimension—even if you intend to use only a single dimension. Otherwise, you will get the following build error: 
意思大體說,這個3.0的插件要求flavor dimension必需要有,哪怕只有一個維度也要聲明, flavorDimensions 是在android{}中的字段:能夠理解成維度,好比下面只聲明瞭一個渠道的維度,學習

flavorDimensions "channel"
    //渠道
    productFlavors {

        qh360 {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "qh360"]
            dimension "channel"
        }
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
            dimension "channel"
        }

    }

關於flavorDimensions 能夠生成多維度,好比下面的代碼gradle

// 兩個維度
flavorDimensions "isFree", "channel"

productFlavors {
     free {
      // 免費和付費用isFree作標識,小米和htc爲發佈到的平臺用channel作標識,於是最後生成4
      //種flavor,加上buildtype就是4*2=8種
      dimension "isFree"
      ...
    }

    paid {
      dimension "isFree"
      ...
    }

    xiaomi{
        dimension "channel"
        ...
    }

    htc{
        dimension "channel"
        ...
    }
}

其實就是在3.0插件之後,google要求必須添加這個flavorDimensions 這個字段哪怕是隻有一個維度也要寫上纔不報錯, 
而後看到stackoverflow上的回答更簡單的使用以下:ui

android {

    defaultConfig {

        flavorDimensions 'default'
    }

或是:google

android {

    defaultConfig {

        flavorDimensions 'versionCode'
    }

版權聲明:本文爲博主在學習工做中所遇到問題解決的點滴記錄,不能說全是原創,若有錯誤之處,歡迎批評指正 https://blog.csdn.net/sinat_35670989/article/details/78393709spa

相關文章
相關標籤/搜索