混合依赖项版本时出错

时间:2018-05-25 10:49:38

标签: android android-gradle dependencies multiple-versions

我收到错误,如图Error Conflict Image 所示。

我尝试了很多链接,并检查了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

请查看。

4 个答案:

答案 0 :(得分:0)

所有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")
    }
  }
}

答案 1 :(得分:0)

这是您的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)
  • 分组

答案 2 :(得分:0)

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

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

您的项目应该使用这些渐变

Google +

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

Google帐户登录

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

Google操作系统,“基本客户端库”

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

Google登录

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

Google Analytics

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

Google Awareness

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

Google Cast

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

Google云消息传递

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

Google云端硬盘

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

Google Fit

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

Google位置和活动识别

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

Google地图

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

Google移动广告

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 Panorama Viewer

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

Google Play游戏服务

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

SafetyNet

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

Android Pay

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

依靠Google操作系统

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

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

答案 3 :(得分:0)

由于您可以检入您的相关性,因此您使用的是不同版本的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版开始,版本号遵循语义版本控制方案。   每个Maven依赖项匹配com.google.android.gms:play-services- *和com.google.firebase:firebase- *不再需要具有相同的版本号才能在构建时正确运行运行时。您将能够彼此独立地升级每个依赖项。

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

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

并将库更新为最新版本。