如果您想了解解决Error:Allflavorsmustnowbelongtoanamedflavordimension.Learnmoreathttps://d.android.com的知识,那么本
如果您想了解解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com、All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools、Anaconda3 tensorflow 安装 及 ModuleNotFoundError: No module named ''tensorflow'' 解答、Android : 代码多维度管理(产品风味) - flavorDimensions & productFlavors的各个方面,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools
- Anaconda3 tensorflow 安装 及 ModuleNotFoundError: No module named ''tensorflow'' 解答
- Android : 代码多维度管理(产品风味) - flavorDimensions & productFlavors
解决Error: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 版本,是2017年7月份最新版本了。
于是我把主程序的build.gradle中的gradle版本改成了这个,具体指定哪个版本我也不知道,于是就写了个3.0+
dependencies { classpath 'com.android.tools.build:gradle:3.0+' }
然后再次编译,又发现了毒。
提示: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
这个一个错误,意思是:所有的flavors都必须属于同一个风格。
=。=懵逼
去翻墙看了它提供的地址才知道:
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之后有一种自动匹配消耗库的机制,便于debug variant 自动消耗一个库,然后就是必须要所有的flavor 都属于同一个维度。
为了避免flavor 不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。
= 。=还是懵逼。说一堆依然不是很理解。
但是我们从中已经知道解决方案了:
在主app的build.gradle里面的
defaultConfig { targetSdkVersion:*** minSdkVersion :*** versionCode:*** versionName :*** //版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了 flavorDimensions "versionCode" }
总结
以上所述是小编给大家介绍的解决Error:All flavors must Now belong to a named flavor dimension. Learn more at https://d.android.com,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
Android studio 报错
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
在 app 的 gradle 中 的 android 下添加
flavorDimensions "versionCode"
compileSdkVersion 28
defaultConfig {
applicationId "com.lanyu96.loadinglayout"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
//解决报错 All flavors must now belong to a named .....
flavorDimensions "versionCode"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools
Android studio 报错
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
在app的gradle中 的 android下添加
flavorDimensions "versionCode"
compileSdkVersion 28
defaultConfig {
applicationId "com.lanyu96.loadinglayout"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
//解决报错 All flavors must now belong to a named .....
flavorDimensions "versionCode"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Anaconda3 tensorflow 安装 及 ModuleNotFoundError: No module named ''tensorflow'' 解答
Anaconda3 的安装,参考:手把手教你如何安装 Tensorflow(Windows 和 Linux 两种版本)
tensorflow 的安装,参考:深度学习(TensorFlow)环境搭建:(三)Ubuntu16.04+CUDA8.0+cuDNN7+Anaconda4.4+Python3.6+TensorFlow1.3
我选的是 CPU 下的安装,参考以上链接安装,如果出现:
①下载的 TensorFlow 对应的 Python 版本一定要和 conda create -n tensorflow python=x.x 的版本一样才行
②在 anaconda3 的包下搜索 "tensorflow",如果搜到,说明是路径没找到 tensorflow.
我的 tensorflow 路径:
需要将该路径临时加入到 sys.path 中:
进入 python 中:
import sys
sys.path #查看 sys.path
sys.path.append("")
import tensorflow # 没有报错
需要将该路径永久加入到 sys.path 中:
在下添加一个路径文件如:mypypath.pth , 必须以.pth 为后缀。
vi mypypath.pth
然后写入:,并保存关闭。
再次进入 python 中:
import tensorflow # 没有报错
参考:
Android : 代码多维度管理(产品风味) - flavorDimensions & productFlavors
一、关于配置产品风味
Android studio 升级到3.0之后,gradle增加了多维度管理配置,便于同一个项目中创建应用的不同版本,分别管理依赖项并签署配置。创建产品风味与创建构建类型类似:只需将它们添加到 productFlavors {}
代码块并配置您想要的设置。产品风味支持与 defaultConfig
相同的属性,这是因为 defaultConfig
实际上属于 ProductFlavor
类。这意味着,您可以在 defaultConfig {}
代码块中提供所有风味的基本配置,每种风味均可更改任何这些默认值,例如 applicationId
。当您创建新模块时,Android Studio 会自动为您创建调试和发布这两种构建类型。尽管调试构建类型不会出现在构建配置文件中,Android Studio 会为其配置 debuggable true
。这样,您可以在安全的 Android 设备上调试应用并使用通用调试密钥库配置 APK 签署。官网示例:
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"
...
}
}
}
...
通过以上配置,就可以编译出多维度apk,以上示例可根据 "api" + "mode" 2个维度分别配置多个产品:
① minApi21 的 demo 、②minApi21 的 full 、③minApi23 的 demo 、④minApi23 的 full 、⑤minApi24 的 demo 、⑥minApi24 的 full
二、小试牛刀
从以上官网介绍可知产品多维度,即是在同一个工程上配置编译出各风味的apk版本,比如:演示用的简化版的和完整功能release版、两个平台UI的差异、多个项目之间功能增减...等等,通过多维度配置就不用一个版本维护一份工程,也不会因判断逻辑太多,导致代码臃肿。下面简单使用一下多版本管理的工具–priductFlavors:
(1)在 build.gradle 中添加自定义的风味维度:
// Specifies a flavor dimension.
flavorDimensions "mode", ''platform''
// 多渠道定义
productFlavors {
orginal {
// Assigns this product flavor to the ''mode'' flavor dimension.
// This step is optional if you are using only one dimension.
dimension "mode"
}
phone {
dimension "platform"
versionNameSuffix "-slide"
}
tv {
dimension "platform"
versionNameSuffix "-button"
}
}
(2)同步、配置:
在build.gradle添加自定义维度同步后,可在 build/generated/source/buildConfig目录下找到对应的产品型号目录(默认是生成当前Build Variant配置的),也分别有debug和release的版本:
添加自定义维度后也可通过Gradle或者在Terminal中使用命令‘gradlew :app:assembleRelease
’直接构建打包,生成对应版本的apk:

(3)代码中获取配置文件"BuildConfig.java"中的各变量来实现对应型号产品特定的功能和逻辑:
上面构建打包的apk内部代码逻辑是有差异的,首先看看生成的 BuildConfig.java 内容,及各版本的差异:
①release和debug版本的差异:
②phone平台和tv平台版本的差异:
因此,在java代码中可以通过如下方式分别实现代码逻辑(以下通过FLAVOR变量控制,也可使用或搭配其他变量):
比如在我本地工具类 Utils.java 中定义了对应的字符串变量,对应 BuildConfig.java中生成的值:
public static final String FLAVOR_Phone = "orginalPhone";
public static final String FLAVOR_Tv = "orginalTv";
然后其它功能类的代码中就可以通过判断当前的配置变量实现对应型号的逻辑:
if (Utils.FLAVOR_Phone.equals(BuildConfig.FLAVOR)) {
//手机平台想实现的代码逻辑
} else if (Utils.FLAVOR_Tv.equals(BuildConfig.FLAVOR)) {
//电视机平台想实现的代码逻辑
} else {
//默认配置平台想实现的代码逻辑
}
此后,便可以通过 Build Variant 来选择某个配置,编译出对应的apk版本,而不用改动或者分别维护一份代码。
-end-
我们今天的关于解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com的分享已经告一段落,感谢您的关注,如果您想了解更多关于All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com、All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools、Anaconda3 tensorflow 安装 及 ModuleNotFoundError: No module named ''tensorflow'' 解答、Android : 代码多维度管理(产品风味) - flavorDimensions & productFlavors的相关信息,请在本站查询。
本文标签: