解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
这个问题是Androidstudio升级到3.0之后,运行的时候会提示gradle要升级到3.5版本才能编译。于是我把我的gradle升级到了
gradle-4.1-milestone-1版本,是2017年7月份最新版本了。
于是我把主程序的build.gradle中的gradle版本改成了这个,具体指定哪个版本我也不知道,于是就写了个3.0+
dependencies{ classpath'com.android.tools.build:gradle:3.0+' }
然后再次编译,又发现了毒。
提示:Error:Allflavorsmustnowbelongtoanamedflavordimension.Learnmoreathttps://d.android.com/r/tools/flavorDimensions-missing-error-message.html
这个一个错误,意思是:所有的flavors都必须属于同一个风格。
=。=懵逼
去翻墙看了它提供的地址才知道:
Plugin3.0.0includesanewdependencymechanismthatautomaticallymatchesvariantswhenconsumingalibrary.Thismeansanapp'sdebugvariantautomaticallyconsumesalibrary'sdebugvariant,andsoon.Italsoworkswhenusingflavors—anapp'sredDebugvariantwillconsumealibrary'sredDebugvariant.Tomakethiswork,thepluginnowrequiresthatallflavorsbelongtoanamedflavordimension—evenifyouintendtouseonlyasingledimension.Otherwise,youwillgetthefollowingbuilderror:
[cpp]viewplaincopy
Error:Allflavorsmustnowbelongtoanamedflavordimension.
Theflavor'flavor_name'isnotassignedtoaflavordimension.
Toresolvethiserror,assigneachflavortoanameddimension,asshowninthesamplebelow.Becausedependencymatchingisnowtakencareofbytheplugin,youshouldnameyourflavordimensionscarefully.Forexample,ifallyourappandlibrarymodulesusethefoodimension,you'llhavelesscontroloverwhichflavorsarematchedbytheplugin.
//Specifiesaflavordimension. flavorDimensions"color" productFlavors{ red{ //Assignsthisproductflavortothe'color'flavordimension. //Thisstepisoptionalifyouareusingonlyonedimension. dimension"color" ... } blue{ dimension"color" ... } }
大致是说,Plugin3.0.0之后有一种自动匹配消耗库的机制,便于debugvariant自动消耗一个库,然后就是必须要所有的flavor都属于同一个维度。
为了避免flavor不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。
=。=还是懵逼。说一堆依然不是很理解。
但是我们从中已经知道解决方案了:
在主app的build.gradle里面的
defaultConfig{ targetSdkVersion:*** minSdkVersion:*** versionCode:*** versionName:*** //版本名后面添加一句话,意思就是flavordimension它的维度就是该版本号,这样维度就是都是统一的了 flavorDimensions"versionCode" }
总结
以上所述是小编给大家介绍的解决Error:Allflavorsmustnowbelongtoanamedflavordimension.Learnmoreathttps://d.android.com,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!