Android dependency ‘xxx‘ has different version for the compile错误解决步骤

Posted yubo_725

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android dependency ‘xxx‘ has different version for the compile错误解决步骤相关的知识,希望对你有一定的参考价值。

今天在androidStudio中构建项目的时候出现如下错误:

Android dependency ‘com.android.support:cardview-v7’ has different version for the compile (27.0.2) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution

上网查了一番资料后整理出如下解决步骤:

  1. 在项目根目录下执行如下命令,将依赖导出到文件:

    ./gradlew app:dependencies > log_depend.txt
    

    以上命令执行完毕后会将当前项目的依赖树导出到log_depend.txt文件

  2. 打开上面的log_depend.txt文件,然后搜索查找版本冲突的库,比如我遇到的是com.android.support:cardview-v7这个库的冲突,那就搜索这个库,然后发现在log_depend.txt中确实出现了两个版本不一样的库,分别被如下库引用了:

  3. 知道是哪个库引用了cardview导致冲突,问题就好解决了,可以直接排除27.0.2这个版本,用下面的方式排除依赖:

    api ('com.facebook.android:facebook-login:4.35.0') 
        exclude group: 'com.android.support', module: 'cardview-v7'
    
    

以上是关于Android dependency ‘xxx‘ has different version for the compile错误解决步骤的主要内容,如果未能解决你的问题,请参考以下文章