Error:Cannot choose between the following configurations of project :*****:
- 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.
满怀欣喜的更新AndroidStudio 3.0后,爆出如上错误?莫要慌张,哥哥来助阵。
在app/build.gradle中找到****的依赖代码,进行如下修改
dependencies {
........
........
// compile project(':*******')
implementation project(':*******')
........
}
原来AndroidStudio 3.0中,compile 指令被替换成implement指令或api 指令
在com.android.tools.build:gradle 3.0 以下版本依赖在gradle 中的声明写法
compile fileTree(dir: 'libs', include: ['*.jar'])
但在3.0后的写法为
implementation fileTree(dir: 'libs', include: ['*.jar'])
或
api fileTree(dir: 'libs', include: ['*.jar'])
在3.0版本中,compile 指令被标注为过时方法,而新增了两个依赖指令,一个是implement 和api,这两个都可以进行依赖添加,但是有什么区别呢?
api 指令
完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。
implement指令
这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。
用api指令编译,Glide依赖对app Module 是可见的,app Module也可以使用Glide依赖
用implement指令编译依赖对app Module 是不可见的,app Module不可以直接使用Glide
建议
在Google IO 相关话题的中提到了一个建议,就是依赖首先应该设置为implement的,如果没有错,那就用implement,如果有错,那么使用api指令,这样会使编译速度有所增快。