解決Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
這個(gè)問題是Android studio升級(jí)到3.0之后,運(yùn)行的時(shí)候會(huì)提示gradle要升級(jí)到3.5版本才能編譯。于是我把我的gradle升級(jí)到了
gradle-4.1-milestone-1 版本,是2017年7月份最新版本了。
于是我把主程序的build.gradle中的gradle版本改成了這個(gè),具體指定哪個(gè)版本我也不知道,于是就寫了個(gè)3.0+
dependencies {
classpath 'com.android.tools.build:gradle:3.0+'
}然后再次編譯,又發(fā)現(xiàn)了毒。
提示:Error:All flavors must now belong to a named flavor dimension.Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
這個(gè)一個(gè)錯(cuò)誤,意思是:所有的flavors都必須屬于同一個(gè)風(fēng)格。
Plugin 3.0.0 includes a new dependency mechanism that automatically matches variants when consuming a library. This means an app's debug variant automatically consumes a library's debug variant, and so on. It also works when using flavors—an app's redDebug variant will consume a library's redDebug variant. To make this work, 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:
[cpp] view plain copy
Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
To resolve this error, assign each flavor to a named dimension, as shown in the sample below. Because dependency matching is now taken care of by the plugin, you should name your flavor dimensions carefully. For example, if all your app and library modules use the foo dimension, you'll have less control over which flavors are matched by the plugin.
// Specifies a flavor dimension.
flavorDimensions "color"
productFlavors {
red {
// Assigns this product flavor to the 'color' flavor dimension.
// This step is optional if you are using only one dimension.
dimension "color"
...
}
blue {
dimension "color"
...
}
} 大致是說,Plugin 3.0.0之后有一種自動(dòng)匹配消耗庫(kù)的機(jī)制,便于debug variant 自動(dòng)消耗一個(gè)庫(kù),然后就是必須要所有的flavor 都屬于同一個(gè)維度。
為了避免flavor 不同產(chǎn)生誤差的問題,應(yīng)該在所有的庫(kù)模塊都使用同一個(gè)foo尺寸。
= 。=還是懵逼。說一堆依然不是很理解。
但是我們從中已經(jīng)知道解決方案了:
在主app的build.gradle里面的
defaultConfig {
targetSdkVersion:***
minSdkVersion :***
versionCode:***
versionName :***
//版本名后面添加一句話,意思就是flavor dimension 它的維度就是該版本號(hào),這樣維度就是都是統(tǒng)一的了
flavorDimensions "versionCode"
}總結(jié)
以上所述是小編給大家介紹的解決Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Intent傳遞對(duì)象之Serializable和Parcelable的區(qū)別
Intent在不同的組件中傳遞對(duì)象數(shù)據(jù)的應(yīng)用非常普遍,大家都知道在intent傳遞對(duì)象的方法有兩種:1、實(shí)現(xiàn)Serializable接口、2、實(shí)現(xiàn)Parcelable接口,接下來通過本文給大家介紹Intent傳遞對(duì)象之Serializable和Parcelable的區(qū)別,感興趣的朋友一起學(xué)習(xí)吧2016-01-01
Android列表實(shí)現(xiàn)(3)_自定義列表適配器思路及實(shí)現(xiàn)代碼
Android 自定義列表適配器會(huì)提供很多的便利;下面的例子為使用自定義的列表適配器來顯示列表,感興趣的朋友可以研究下2012-12-12
Android開發(fā)中WebView的詳細(xì)使用方法和常見操作
這篇文章詳細(xì)介紹了Android中WebView組件的使用方法和常見操作,包括基本初始化、啟用JavaScript、處理頁(yè)面導(dǎo)航、與JavaScript交互、加載本地HTML內(nèi)容、文件上傳與下載、進(jìn)度條與加載指示、處理網(wǎng)頁(yè)錯(cuò)誤以及安全性設(shè)置,需要的朋友可以參考下2024-11-11
Flutter手機(jī)權(quán)限檢查與申請(qǐng)實(shí)現(xiàn)方法詳解
使用flutter進(jìn)行app開發(fā),一定會(huì)用到手機(jī)的部分權(quán)限,包括通知推送、定位、相冊(cè)、存儲(chǔ)、相機(jī)、麥克風(fēng)等。而權(quán)限的檢查和獲取,最受歡迎的就是通過permission_handler這個(gè)插件來實(shí)現(xiàn)2022-11-11
Android即時(shí)通訊設(shè)計(jì)(騰訊IM接入和WebSocket接入)
本文主要介紹了Android即時(shí)通訊設(shè)計(jì)(騰訊IM接入和WebSocket接入),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
詳解Android App中創(chuàng)建ViewPager組件的方法
這篇文章主要介紹了詳解Android App中創(chuàng)建ViewPager組件的方法,ViewPager最基本的功能就是可以使視圖滑動(dòng),需要的朋友可以參考下2016-03-03
WebView設(shè)置WebViewClient的方法
這篇文章主要介紹了 WebView設(shè)置WebViewClient的方法的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-09-09
Android Intent傳遞對(duì)象的兩種方法(Serializable,Parcelable)詳細(xì)介紹
這篇文章主要介紹了Android Intent傳遞對(duì)象的兩種方法(Serializable,Parcelable)詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-12-12
XrecyclerView實(shí)現(xiàn)加載數(shù)據(jù)和切換不同布局
這篇文章主要為大家詳細(xì)介紹了XrecyclerView實(shí)現(xiàn)加載數(shù)據(jù)、切換不同布局功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

