Error:Unable to resolve dependency for ':app@stage/compileClasspath': Could not resolve project :mvp
来源:互联网 发布:淘宝创业故事 编辑:程序博客网 时间:2024/06/05 08:46
关于Android Studio 3.0升级Gradle编译报错:Error:Unable to resolve dependency for ‘:app@stage/compileClasspath’: Could not resolve project :mvp.
这个问题在Android Studio3.0之前是不存在的。老版本可以放心使用。
根据错误日志(日志我先不放出来),我发现这个问题是依赖库的BuildType
缺少相关配置造成的。所以我检查了项目中的build.gradle
文件。
升级3.0之前,我在app/build.gradle
的配置如下:
buildTypes { stage { //... } release { //... }}
可以看到,我配置了两种编译类型stage
和release
。
在项目中,我的app
模块依赖了mvp
模块。
但是我在mvp
模块中只配置了一种编译类型release
:
buildTypes { release { //... } }
这在AS 3.0中就造成了编译报错。
如何解决呢?
在mvp
模块中也同样配置一个stage
编译类型就可以了!!如下:
//mvp模块中的`stage`和`release`里的配置信息没必要和app模块的一样。buildTypes { stage { //... } release { //... }}
配置好之后右上角经典的Try Again
。你会惊奇的发现,编译通过了!!
其实最简单的解决方式就是让你的依赖库和被依赖库中拥有相同元素(配置不同没事)的buildTypes
。
读到这里,我再放出错误日志,相信你一定能一目了然了!
Could not resolve project :mvp.Required by: project :app//这里提示project是app模块。 > Unable to find a matching configuration of project :mvp://这里说明了mvp模块不能跟project模块(app模块)的配置相匹配。 - Configuration 'debugApiElements': - Required com.android.build.api.attributes.BuildTypeAttr 'stage' and found incompatible value 'debug'.//这里指出了问题所在。mvp模块中需要名为'stage'的BuildTypeAttr。(mvp模块中已经存在了'debug'以及下面指出的'release',debug是默认自带的buildTypes类型) - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required. - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'. - Configuration 'debugRuntimeElements': - Required com.android.build.api.attributes.BuildTypeAttr 'stage' and found incompatible value 'debug'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required. - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'. - Configuration 'releaseApiElements': - Required com.android.build.api.attributes.BuildTypeAttr 'stage' and found incompatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required. - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'. - Configuration 'releaseRuntimeElements': - Required com.android.build.api.attributes.BuildTypeAttr 'stage' and found incompatible value 'release'. - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'. - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required. - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
如果这样配置之后,你的项目还报出类似的错误,就需要你阅读下面的姿势了。
在Android Studio3.0之后,你的项目被依赖的模块的buildTypes
种类必须是依赖模块的超集!才会避免出现这个问题!
举个例子:有A、B两个模块。A模块依赖了B模块,A 模块里buildType
有buildType_1
和buildType_2
//A模块buildTypes { buildType_1 { //...... } buildType_2 { //...... }}
- 情况1:B模块里也有
buildType_1
和buildType_2
。这是没问题的。
//B模块buildTypes { buildType_1 { //...... } buildType_2 { //...... }}
- 情况2:B模块里有
buildType_1
、buildType_2
和buildType_3
。这样也是没问题的。因为B是A的超集嘛。
//B模块buildTypes { buildType_1 { //...... } buildType_2 { //...... } buildType_3 { //...... }}
- 情况3:B模块里只有
buildType_1
。这样的配置在编译时就会报出上面的错误。
//B模块buildTypes { buildType_1 { //...... }}
- 情况4:B模块里有
buildType_5
。这样也会报错。
//B模块buildTypes { buildType_5 { //...... }}
当然,在开发过程中我们很可能一个模块依赖另一个,而另一个模块又依赖了其他模块。如果你的项目中出现了这个错误,并且模块的依赖关系树也比较长,就需要按照上面所说的buildTypes
超集关系,重新配置下你的各个模块吧。
总结
升级之后,Gradle在构建项目的时候应该是根据依赖关系进行了一次检查。为什么要这样做这个检查,我想是为了在打包的时候,敲一个gradle assembleStage
命令就可以让各个模块buildTypes的stage
配置生效(虽然都叫stage
,但是配置内容可能不同呦 ~ ~),这样就更方便的打包了。
- Error:Unable to resolve dependency for ':app@stage/compileClasspath': Could not resolve project :mvp
- 升级AndroidStudio3.0 Unable to resolve dependency for ':app@betaUnitTest/compileClasspath': Could not
- 升级AndroidStudio3.0 Unable to resolve dependency for ':app@betaUnitTest/compileClasspath': Could not
- Android 异常Error:Unable to resolve dependency ,Could not resolve project
- [ERROR] Failed to execute goal on project sypro: Could not resolve dependencies for project sy.demo:
- [ERROR] Failed to execute goal on project jdong: Could not resolve dependencies for project jdong:ja
- Maven error: Failed to execute goal on project : Could not resolve dependencies for project 解决办法
- 关于Could not resolve dependencies for project
- Maven:Could not resolve dependencies for project
- Could not resolve dependencies for project . Could not find artifact
- Failed to execute goal on project mycollab-config: Could not resolve dependencies for project com.es
- Failed to execute goal on project ecz-wx: Could not resolve dependencies for project
- Failed to execute goal on project finance-weibo: Could not resolve dependencies for project
- 解决:Failed to execute goal on project aopcore: Could not resolve dependencies for project com.cmos:
- maven出现:Failed to execute goal on project ...: Could not resolve dependencies for project ...
- Error:A problem occurred configuring project ':app'. > Could not resolve all
- Could not resolve dependencies for project : Failure to find jar was cached in the local reposit
- Jenkins 构建报错 Could not resolve dependencies for project
- 伪随机数rand()与srand()学习心得
- MySQL练习时所遇问题
- IDA动态调试技术及Dump内存
- Java 技术之垃圾回收机制
- Java主流几大框架的对比(EasyUI,Bootstrap,Struts2,SpingMvc,Ejb,Spring,Hibernate,Mybatis)
- Error:Unable to resolve dependency for ':app@stage/compileClasspath': Could not resolve project :mvp
- 哲学家就餐问题的思考(java实现)
- C# Webservice XML通信的基本方法(一 Webservice 接口的使用)
- parqute orc 存储文件格式
- 推荐几本经典计算机书籍
- Android 内存泄漏总结及如何避免
- Groovy常用语法总结
- async_read_until函数以及streambuf如何使用
- 边框加上阴影,内外阴影都有