【问题标题】:Getting error while mixing dependencies versions混合依赖版本时出错
【发布时间】:2018-11-04 18:04:13
【问题描述】:

我收到一个错误,如下图

我已经尝试了很多链接并检查了 stackoverflow 上的内容并设法解决了大部分问题,但没有完全解决。有没有更简单的方法来解决这个版本混合部分。

下面是我的 gradle 文件

    /**********My Gradle ************************/
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}



android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.example.company"
        minSdkVersion 15
        versionCode 8  //Update on store 25th may 18
        versionName "2.1"

        targetSdkVersion 26
        multiDexEnabled true

    }



    dexOptions {
        javaMaxHeapSize "4g"
    }

    /*buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }*/
    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    useLibrary 'org.apache.http.legacy'

}

dependencies {
    implementation files('libs/jxl-2.6.10.jar')
    /*implementation 'com.android.support:appcompat-v7:23.1.1'*/

    implementation files('libs/ksoap2-android-assembly-3.4.0-jar-with-dependencies.jar')



    implementation 'com.android.support:design:24.2.1'
    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation 'com.android.support:cardview-v7:26.0.0'
    implementation 'com.google.android.gms:play-services-basement:10.2.1'
    implementation 'com.google.android.gms:play-services:10.2.1'
    implementation 'com.android.support:support-v4:26.0.0'
    implementation 'com.github.bumptech.glide:glide:3.6.0'
    implementation 'com.android.support:multidex:1.0.0'
    implementation 'com.google.android.gms:play-services-location:9.6.1'
    implementation 'com.google.android.gms:play-services-maps:9.6.1'
    implementation 'com.google.android.gms:play-services:9.6.1'
    implementation 'com.google.android.gms:play-services-identity:9.6.1'
    implementation 'com.google.android.gms:play-services-plus:9.6.1'
    implementation 'com.github.boxme:squarecamera:1.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
//    implementation 'com.google.firebase:firebase-messaging:10.2.1'
    implementation 'com.google.firebase:firebase-messaging:11.0.4'
    implementation 'id.zelory:compressor:2.1.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.android.support:multidex:1.0.0'
    /*implementation 'net.hockeyapp.android:HockeySDK:5.0.1'*/
    implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true;
    }
}

apply plugin: 'com.google.gms.google-services'

以下是我的错误日志:

 org.gradle.api.GradleException: Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 10.2.1.
    at com.google.gms.googleservices.GoogleServicesTask.checkVersionConflict(GoogleServicesTask.java:161)
    at com.google.gms.googleservices.GoogleServicesTask.action(GoogleServicesTask.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at 

我浏览了下面的帖子并设法解决了一些错误,但不是完全 Mixing dependencies versions

.

请查看。

【问题讨论】:

    标签: android android-gradle-plugin dependencies multiple-versions


    【解决方案1】:

    所有 Google 依赖项都应具有相同的版本。 将以下内容添加到您的 App build.gradle:

    configurations.all {
    
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.getRequested().getGroup() == 'com.google.android.gms') {
            // If different projects require different versions of
            // Google Play Services it causes a crash on run.
            // Fix by overriding version for all projects.
            details.useVersion("15.0.1")
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      这是您的 gradle 依赖项的工作版本:

      // All com.android.support versions the same
      implementation 'com.android.support:appcompat-v7:26.1.0' // Don't use variable versions '+'
      implementation 'com.android.support:design:26.1.0'
      implementation 'com.android.support:appcompat-v7:26.1.0'
      implementation 'com.android.support:cardview-v7:26.1.0'
      implementation 'com.android.support:support-v4:26.1.0'
      
      // All com.google.android.gms versions the same
      implementation 'com.google.android.gms:play-services-basement:15.0.1'
      implementation 'com.google.android.gms:play-services-location:15.0.1'
      implementation 'com.google.android.gms:play-services-maps:15.0.1'
      implementation 'com.google.android.gms:play-services-identity:15.0.1'
      implementation 'com.google.android.gms:play-services-plus:15.0.1'
      
      implementation 'com.google.android.gms:play-services:12.0.1' // Don't implement repos multiple times
      implementation 'com.google.firebase:firebase-messaging:15.0.2'
      implementation 'com.android.support:multidex:1.0.0' // Don't implement repos multiple times
      implementation 'com.android.support.constraint:constraint-layout:1.1.0' // Don't use alpha versions
      
      implementation 'com.github.bumptech.glide:glide:3.6.0'
      implementation 'com.squareup.picasso:picasso:2.5.2'
      
      implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
      /*implementation 'net.hockeyapp.android:HockeySDK:5.0.1'*/
      
      implementation 'com.github.boxme:squarecamera:1.1.0'
      implementation 'id.zelory:compressor:2.1.0'
      implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
          transitive = true
      }
      

      小贴士:

      • 除非您知道自己在做什么,否则不要使用 alpha 或 beta 版本
      • 不要使用可变版本名称 (26.+),使用常量版本名称 (26.0.0)
      • 使用最新版本
      • 分组相同版本依赖(com.android.support)

      【讨论】:

        【解决方案3】:

        要解决此错误,您需要为所有 google play 服务使用相同的 gradle 版本

        最好使用最新版本(Go to sdk>tools - Check the Google play services >Update it

        对于您的项目,您应该使用这些 gradles

        Google+

        com.google.android.gms:play-services-plus:15.0.1
        

        Google 帐户登录

        com.google.android.gms:play-services-auth:15.0.1
        

        Google Actions,`Base Client Library

        com.google.android.gms:play-services-base:15.0.1`
        

        谷歌登录

        com.google.android.gms:play-services-identity:15.0.1
        

        谷歌分析

        com.google.android.gms:play-services-analytics:15.0.2
        

        Google 认知度

        com.google.android.gms:play-services-awareness:15.0.1
        

        Google Cast

        com.google.android.gms:play-services-cast:15.0.1
        

        谷歌云消息传递

        com.google.android.gms:play-services-gcm:15.0.1
        

        Google 云端硬盘

        com.google.android.gms:play-services-drive:15.0.1
        

        Google 健身

        com.google.android.gms:play-services-fitness:15.0.1
        

        Google 位置和活动识别

        com.google.android.gms:play-services-location:15.0.1
        

        谷歌地图

        com.google.android.gms:play-services-maps:15.0.1
        

        谷歌移动广告

        com.google.android.gms:play-services-ads:15.0.1
        

        Google 地方信息

        com.google.android.gms:play-services-places:15.0.1
        

        移动视觉

        com.google.android.gms:play-services-vision:15.0.2
        

        Google 附近

        com.google.android.gms:play-services-nearby:15.0.1
        

        Google 全景查看器

        com.google.android.gms:play-services-panorama:15.0.1
        

        Google Play 游戏服务

        com.google.android.gms:play-services-games:15.0.1
        

        安全网

        com.google.android.gms:play-services-safetynet:15.0.1
        

        Android Pay

        com.google.android.gms:play-services-wallet:15.0.1
        

        Wear OS by Google

        com.google.android.gms:play-services-wearable:15.0.1
        

        参考 https://developers.google.com/android/guides/setup

        【讨论】:

          【解决方案4】:

          您可以检查您的依赖项,您使用的是不同版本的 google play 服务和 firebase 库

          implementation 'com.google.android.gms:play-services:10.2.1'
          implementation 'com.google.android.gms:play-services-location:9.6.1'
          implementation 'com.google.firebase:firebase-messaging:11.0.4'
          

          使用相同的版本。

          否则请检查此official blog

          从所有 Play 服务和 Firebase 库的第 15 版开始,版本号遵循语义版本控制方案。 每个匹配 com.google.android.gms:play-services-* 和 com.google.firebase:firebase-* 的 Maven 依赖项不再需要具有相同的版本号才能在构建时和运行时。您将能够相互独立地升级每个依赖项。

          将google play gradle插件版本更新到最新版本,目前为3.3.+。

          classpath 'com.google.gms:google-services:3.3.1'
          

          并将库更新到最新版本。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-12-25
            • 2016-09-18
            • 1970-01-01
            • 1970-01-01
            • 2018-03-23
            相关资源
            最近更新 更多