首页 > 其他分享 >技巧篇 之 这可能是解决 Could not resolve X 最有效的办法之一咯。

技巧篇 之 这可能是解决 Could not resolve X 最有效的办法之一咯。

时间:2022-11-10 21:09:14浏览次数:40  
标签:resolve 技巧 implementation support 依赖 android com Could


夜深人静,远离了城市的喧嚣,开启了个人的狂欢。



技巧篇 之 这可能是解决  Could not resolve X 最有效的办法之一咯。_ide


前言

本文扯皮话较多,主要记录下心路历程,勿喷。

事情的开始,源于某天下发了一个维护老项目的任务。

当时那个头大,依稀记得刚入职便在这个项目哼哧哼哧搞了好久,而最后因为某些原因,项目直接跑不起来了,索性直接本地干掉,专心整现有项目了。

The start

行云流水般导入,编译,准备 build 成功后开始一通霍霍。事实告诉我,小伙子还是忒年轻。

喏。

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.+.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.+.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.+.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.+.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.+.
Show Details
Affected Modules: app

INFO: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: app

ummm,能脑补下当时尴尬的画面么?

Fuck Road

第一想法,肯定又是哪儿依赖了低版本的库了。问下 Google 老兄,得到几乎大部分的解决方案如下:

  • 将项目中所有 support 库版本指定为 26.+,并且将项目 compileSdkVersion 以及 targetSdkVersion 指定为 26。(哎,指标不治本啊,有的 api 引用的高版本的啊)
  • 将 gradle 设置为离线模式。(我就很是纳闷,依赖的事儿,咋和 gradle 相关呢)
  • 还有重装 AS。。。(听着不靠谱,Bye)

也可能是对于基本的搜索技能还处于小 low B 一个,经过一天的挣扎,成功给我干郁闷了。

Google 估计对我都无奈了。

遂只能自己看看哪儿块依赖使用了 com.android.support:appcompat-v7:26.+,检查很久,当时项目 support 相关配置如下:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'

都是引入的 27.1.1 版本库,接着继续在项目中翻腾,翻腾。。。

突然看到一个 Version Config Gradle,内容如下:

ext {
cfgs = [
compileSdkVersion : 27,
buildToolsVersion : "27.1.1",
minSdkVersion : 21,
targetSdkVersion : 27,
versionCode : 10,
versionName : "2.0.0",
ucropVersionCode : 22,
ucropVersionName : "2.2.0-native",

//open version control
androidSupportVersion: "27.1.1",
glide : "4.5.0",
rxjava : "2.0.5",
rxandroid : "2.0.1"
]
}

也是鸡老大提醒,是否引入依赖未生效呢?

为了防止配置版本引用失效,这里直接讲其他依赖库修改为制定版本(此处原先应用配置文件中的版本,现已修改为指定版本号):

dependencies {
// 此处为某个依赖 Module 中引入的依赖
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation "com.github.bumptech.glide:glide:${cfgs.glide}"
}

再次 Build,依旧傲然挺立,我能怎么办?

忽然想起鸡老大说,有没有可能是引入第三方 Module 中又引入了其他的依赖源呢?

一脸懵逼的继续在项目中翻腾,翻腾。忽然想到,Android Studio 不是为我们提供了很多现有强大的小插件么?直接打印项目中的所有依赖流检查一边不就好了吗?

右侧找到 app —> help —> dependencies,狂点:

技巧篇 之 这可能是解决  Could not resolve X 最有效的办法之一咯。_Could not resolve_02


随后听到 Air 不堪重负的风扇狂飙,

标签:resolve,技巧,implementation,support,依赖,android,com,Could
From: https://blog.51cto.com/u_13346181/5842072

相关文章