在运行时遇到错误,包含名称为“com.google.android.gms”的多个库

时间:2016-11-15 12:42:26

标签: android android-gradle google-play-services build.gradle

Android studio 2.2.2

说默认依赖关系= compile 'com.google.android.gms:play-services:9.8.0'

我在运行时遇到这个错误:

Error:java.lang.RuntimeException: Error: more than one library with package name 'com.google.android.gms'

当我尝试用我在项目中需要的特定依赖项替换默认的play服务依赖项时,以减少执行时间。

这是我的应用级gradle文件:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    useLibrary 'org.apache.http.legacy'

    lintOptions {
        checkReleaseBuilds false
    }

    defaultConfig {
        applicationId "com.blucursor.gpstrack"
        minSdkVersion 19
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 16
        versionName "2.0"
        resConfigs "en", "fr"

    }

    signingConfigs {
        release {
             storeFile file("C:\\******\\********.jks")
             storePassword "********"
             keyAlias "*******"
             keyPassword "******"
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
            zipAlignEnabled true

        }
    }
}

dependencies {

    compile files('libs/android-query-full.0.26.8.jar')
    compile files('libs/GraphView-4.0.1.jar')
    //compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.google.android.gms:play-services-gcm:9.8.0'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:cardview-v7:25.0.0'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    compile 'com.google.maps.android:android-maps-utils:0.3'
    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.moxun:tagcloudlib:1.1.3'
    compile 'io.realm:realm-android:0.84.1'
}
apply plugin: 'com.google.gms.google-services'

这是项目级gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.google.gms:google-services:3.0.0'

    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

当我使用默认构建时,这工作正常,即: compile 'com.google.android.gms:play-services:9.4.0'

我尝试了什么: 我跟随的来源。

我见过很多解决方案,说你要么必须使用播放服务依赖项,要么使用特定的依赖项。 我试图做同样的事情,但它似乎并不适合我。 对此有何帮助?

编辑:即使删除了所有Play商店依赖项,也会出现相同的错误。

我还尝试更新app.iml文件并删除了其他不需要项目的Playstore依赖项,但这仍然无效。

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,但我这样做了

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0' //use this version as the newest version
    }

我也这样做了

 dependencies {
.
.
.
    //    compile project(':google-play-services') comment because this version isn't same with my firebase version, try to get the last google-play-service jar / compile the last version
    compile 'com.google.android.gms:play-services:10.2.0'
    compile ('com.google.firebase:firebase-messaging:10.2.0'){
            exclude group: 'com.google.android.gms', module: 'com.google.android.gms'
        }
    }
    apply plugin: 'com.google.gms.google-services' // i do it on every project i have

然后,同步您的项目并清理您的项目 这可能对你有所帮助,我认为google-play-service的版本应与firebase版本相同

更新

尝试使你的gms版本与firebase版本相同(如果你使用9.8.0 in gms,在firebase中使用9.8.0)

答案 1 :(得分:-2)

从项目级gradle文件

删除此行classpath'com.google.gms:google-services:3.0.0'。

因为您已在app level gradle文件中使用。