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
1019 0
RN运行项目Error:Unable to resolve module
|
1月前
|
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
19 1
|
11月前
|
Java Maven
解决Maven中CANNOT Resolve XXX错误
解决Maven中CANNOT Resolve XXX错误
300 0
|
11月前
|
网络协议
出现“Could not resolve host: www.github.com; Unknown error”错误解决
出现“Could not resolve host: www.github.com; Unknown error”错误解决
422 0
|
开发工具 git
完美解决 fatal: unable to access ‘https://github.com/.../.git‘: Could not resolve host: github.com
完美解决 fatal: unable to access ‘https://github.com/.../.git‘: Could not resolve host: github.com
15508 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‘
846 0
|
JavaScript
Vue 安装 element-ui时报错 code ERESOLVE unable to resolve dependency tree
Vue 安装 element-ui时报错 code ERESOLVE unable to resolve dependency tree
714 0
Vue 安装 element-ui时报错 code ERESOLVE unable to resolve dependency tree
|
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
709 0
[ERROR] Failed to execute goal on project springcloud: Could not resolve dependencies for project co
|
应用服务中间件 nginx 网络协议