FAQ:

All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

解决:

看官方文档:

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:

2.Flavor Dimensions变更

Android Plugin3.0的依赖机制:在使用library时会自动匹配variant(debug, release),就是说app的debug会自动匹配library的debug,相信大多数人也像我一样,当library多了,不会手动选择每个Library的variant。现在好了,它会自动匹配了。同样如果使用flavor的时候,比如app的redDebug同样会自动匹配library的readDebug。虽然有这样的优势,但是在使用flavor时,必须定义flavor dimension,否则会提示错误:

Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
  • 这个错误,我也已经在使用Android Studio3.0以后碰到好多次了。现在使用flavor,必须像下面一样配置:
// 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"
...
}
}
  • 注意:如果library有两个dimensions:color,shape,但是app只有color,那么会如下的编译错误:
Error:Could not resolve all dependencies for configuration ':bar:redDebugCompileClasspath'.
Cannot choose between the following configurations on project :foo:
- redCircleDebugApiElements
- redSquareDebugApiElements
...
  • 在APP使用flavorSelection选定使用某个flavor dimension,注意如下配置:
android {
...
// The flavorSelection property uses the following format:
// flavorSelection 'dimension_name', 'flavor_name' // Chooses the 'square' flavor from libraries that specify a 'shape'
// dimension.
flavorSelection 'shape', 'square'
}

ref docs:
迁移到Android Studio 3.0
http://blog.csdn.net/ncuboy045wsq/article/details/73521856
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

 

All flavors must now belong to a named flavor dimension的更多相关文章

  1. Error:All flavors must now belong to a named flavor dimension.

    环境 android studio 3.0 错误 Error:All flavors must now belong to a named flavor dimension. 解决 在build.gr ...

  2. 安卓 android studio 报错 All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com

    这个问题是Android studio升级到3.0之后,运行的时候会提示gradle要升级到3.5版本才能编译.于是我把我的gradle升级到了 gradle-4.1-milestone-1 版本,是 ...

  3. 解决Error:All flavors must now belong to a named flavor dimension. Learn more at...

    低版本的gradle里面不会出现这个错误,高版本出现,不多说,看如何解决 在defaultConfig{}中添加:flavorDimensions "default" 保证所有的f ...

  4. 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com

    主app的build.gradle里面的 defaultConfig { targetSdkVersion:*** minSdkVersion :*** versionCode:*** version ...

  5. 更新Android Studio 3.0碰到的问题

    更新完后试下运行正在维护的旧项目,出现各种错误,因为后来发现问题不在这,所以没记完整,大概如下: A larger heap for the Gradle daemon is recommended ...

  6. Android之友盟多渠道打包与数据统计

    文章大纲 一.多渠道打包与数据统计介绍二.友盟实现多渠道打包实战三.友盟数据统计实战四.项目源码下载五.参考文章   一.多渠道打包与数据统计介绍   多渠道打包,相信很多同学都知道.在Android ...

  7. Android Studio 常见问题及解决方法

    一.Error:All flavors must now belong to a named flavor dimension 问题描述: Error:All flavors must now bel ...

  8. 升级到 Android Studio 3.0 + Gradle 4.1 遇到的一些坑及解决方案

    问题一: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkD ...

  9. gradle tool升级到3.0注意事项

    Gradle版本升级 其实当AS升级到3.0之后,Gradle Plugin和Gradle不升级也是可以继续使用的,但很多新的特性如:Java8支持.新的依赖匹配机制.AAPT2等新功能都无法正常使用 ...

随机推荐

  1. Flink架构分析之资源分配

    Task Slot     Flink中每个真正执行任务的TaskManager都是一个JVM进程,其在多线程环境中执行一个或者多个子任务.为了控制一个JVM同时能运行的任务数量,flink引入了ta ...

  2. C++STL 中的容器整体/逐元素操作方法 少写80%for循环

    本文中示例代码默认已引用 std 命名空间 累加 (std::accumulate) accumulate(begin, end, init, op) 返回给定区间内元素的累加值与给定初值的和,初值不 ...

  3. 最新Python笔试题2017 涵盖知识面广泛

    引言 想找一份Python开发工作吗?那你很可能得证明自己知道如何使用Python.下面这些问题涉及了与Python相关的许多技能,问题的关注点主要是语言本身,不是某个特定的包或模块.每一个问题都可以 ...

  4. Python数据分析工具库-Numpy 数组支持库(二)

    1 shape变化及转置 >>> a = np.floor(10*np.random.random((3,4))) >>> a array([[ 2., 8., 0 ...

  5. 第十周psp作业

    本周psp 本周进度条 代码累积折线图 博文字数累积折线图 饼状图

  6. windows和RedHat双系统安装说明

    该博客记录了安装windows和RedHat双系统的方法.这里的windows系统是win8.1,RedHat是RHEL-server-7.0-x86_64-LinuxProbe.Com.iso,该i ...

  7. ns3 模拟无线网络通信

    /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * This program is fre ...

  8. 基于MongoDB2.6版本配置MongoDB主从复制集群架构

    1:集群环境说明:mongodb1:192.168.43.10.mongodb2:192.168.43.11.mongodb3:192.168.43.12.且基于主机名相互通信/etc/hosts文件 ...

  9. 软工网络15团队作业8——Beta阶段敏捷冲刺(Day2)

    提供当天站立式会议照片一张 每个人的工作 1.讨论项目每个成员的昨天进展 赵铭: 根据计划安排,继续学习数据库. 吴慧婷:做Beta阶段的计划,并为界面设计寻找素材,学习界面优化. 陈敏: 根据任务, ...

  10. jmeter 常用内置变量

    1. vars   API:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html vars.get(& ...