Coder Social home page Coder Social logo

blogs's People

Watchers

 avatar  avatar

blogs's Issues

解决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:

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" }

就直接解决这个问题。然后app 就可以happy的运行起来了。

原文地址:https://blog.csdn.net/SYIF88/article/details/75009663

升级到Android studio 3.0 后apt报错解决

1.现象描述
原来项目在Android studio 2.3一切正常,升级3.0之后报如下错误:
`Error:Cannot choose between the following configurations of project :android_sdk:

  • debugApiElements
  • debugRuntimeElements
  • releaseApiElements
  • releaseRuntimeElements
    All of them match the consumer attributes:
  • Configuration 'debugApiElements':
    • Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
    • Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  • Configuration 'debugRuntimeElements':
    • Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
    • Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
  • Configuration 'releaseApiElements':
    • Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
    • Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  • Configuration 'releaseRuntimeElements':
    • Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
    • Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
    • Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.`

2.解决办法:
project的build.gradle文件中删除
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

module的build.gradle文件中删除
apply plugin: 'com.neenbedankt.android-apt'

module的build.gradle文件中替换
//apt 'com.jakewharton:butterknife-compiler:8.0.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'

原文地址:https://blog.csdn.net/QQCrazyBoy/article/details/77900183

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.