Unable to resolve dependency for xxx, Could not resolve project

Posted BennuCTech

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unable to resolve dependency for xxx, Could not resolve project相关的知识,希望对你有一定的参考价值。

我们为了在不同的环境使用不同的配置,所以会在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'
    

关注公众号:BennuCTech,发送“暗时间”获取程序员必读经典书籍《暗时间》电子版。

以上是关于Unable to resolve dependency for xxx, Could not resolve project的主要内容,如果未能解决你的问题,请参考以下文章

ERESOLVE unable to resolve dependency tree

Android Studio 3.0——unable to resolve dependency for cordovalib

Unable to resolve dependency for xxx, Could not resolve project

Unable to resolve dependency tree error when installing npm packages

解决Vue项目: verbose stack Error: unable to resolve dependency tree

npm install 报错:verbose stack Error: unable to resolve dependency tree