Unable to resolve dependency for xxx, Could not resolve project

简介: 我们为了在不同的环境使用不同的配置,所以会在gradle中添加buildtypes来区分环境,并且在下面进行不同的配置

我们为了在不同的环境使用不同的配置,所以会在gradle中添加buildtypes来区分环境,并且在下面进行不同的配置,比如:


buildTypes {
    dev{
        signingConfig signingConfigs.DevConfig
        buildConfigField("String", "HOST", "\"http://120.0.0.1:8000/\"")
    }
    debug {
        signingConfig signingConfigs.DebugConfig
        buildConfigField("String", "HOST", "\"http://xxxx.xxx.com/\"")
    }
    release {
        minifyEnabled false
        signingConfig signingConfigs.ReleaseConfig
        buildConfigField("String", "HOST", "\"http://xxxx.xxx.com/\"")
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
复制代码


但是当我们新增一个buildtypes的时候,刷新gradle会发现出错:


Error:Unable to resolve dependency for 'xxxx', Could not resolve project :xxxx

这是因为主项目依赖来一个子项目implementation project(":xxx"),而这个子项目中没有这个buildtypes。

解决方法有几种:

  • gradle降级
  • 子项目中添加该buildtypes,内容可以为空
  • 添加matchingFallbacks

这里前两种都不完美,第三种是最推荐的方法,修改后如下:


buildTypes {
    dev{
        signingConfig signingConfigs.MyConfig
        buildConfigField("String", "PROFILE_HOST", "\"http://114.215.83.151:10008/\"")
        matchingFallbacks = ["debug"]
    }
    debug {
        signingConfig signingConfigs.MyConfig
        buildConfigField("String", "PROFILE_HOST", "\"http://xxxx.xxx.com/\"")
    }
    release {
        minifyEnabled false
        signingConfig signingConfigs.MyConfig
        buildConfigField("String", "PROFILE_HOST", "\"http://xxxx.xxx.com/\"")
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


目录
相关文章
|
移动开发 前端开发
RN运行项目Error:Unable to resolve module
RN运行项目Error:Unable to resolve module
1094 0
RN运行项目Error:Unable to resolve module
bug:The following dependencies are imported but could not be resolved lib-flexibleflexible
bug:The following dependencies are imported but could not be resolved lib-flexibleflexible
1064 0
|
3月前
|
JavaScript 编译器
成功解决:Module build failed: Error: Vue packages version mismatch
这篇文章记录了解决Vue项目中遇到的"Module build failed: Error: Vue packages version mismatch"错误的步骤,原因是项目中Vue依赖的版本不一致,解决方法是删除`node_modules`后重新安装指定版本的Vue和`vue-template-compiler`,确保版本匹配,最终成功运行项目。
成功解决:Module build failed: Error: Vue packages version mismatch
|
6月前
|
Android开发
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.suppor
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.suppor
42 1
|
Java Maven
解决Maven中CANNOT Resolve XXX错误
解决Maven中CANNOT Resolve XXX错误
497 0
|
6月前
Parsing error: No Babel config file detected for XXXXX
Parsing error: No Babel config file detected for XXXXX
|
11月前
|
JavaScript
Error: Unsupported URL Type: npm:fork-ts-checker-webpack-plugin@^5.0.11
如果你去搜索,答案都是去升级你的npm 在StackOverflow说是vue3得在非vue-cli环境得单独配置。地址: 还有说npm install --save-dev fork-ts-checker-webpack-plugin 众说纷纭,都解决不了
117 0
|
Shell Go
goland 解决 cannot resolve directory 'xxxx'/ cannot resolve xxx 问题
goland 解决 cannot resolve directory 'xxxx'/ cannot resolve xxx 问题
goland 解决 cannot resolve directory 'xxxx'/ cannot resolve xxx 问题
|
JavaScript
Module not found: Error: Can‘t resolve ‘path‘
Module not found: Error: Can‘t resolve ‘path‘
974 0
|
Java Maven
[ERROR] Failed to execute goal on project springcloud: Could not resolve dependencies for project co
[ERROR] Failed to execute goal on project springcloud: Could not resolve dependencies for project co
776 0
[ERROR] Failed to execute goal on project springcloud: Could not resolve dependencies for project co