运行时多个程序包名为';com.google.android.gms';

运行时多个程序包名为';com.google.android.gms';,android,android-gradle-plugin,google-play-services,build.gradle,Android,Android Gradle Plugin,Google Play Services,Build.gradle,Android studio 2.2.2 假设默认依赖项=compile'com.google.android.gms:play services:9.8.0' 我在运行时遇到以下错误: 错误:java.lang.RuntimeException:错误:多个程序包名为“com.google.android.gms”的库 当我试图用项目中需要的特定依赖项替换默认的play services依赖项以减少执行时间时 这是我的应用程序级渐变文件: apply plugin: 'com.android.a

Android studio 2.2.2


假设默认依赖项=
compile'com.google.android.gms:play services:9.8.0'

我在运行时遇到以下错误:

错误:java.lang.RuntimeException:错误:多个程序包名为“com.google.android.gms”的库

当我试图用项目中需要的特定依赖项替换默认的play services依赖项以减少执行时间时

这是我的应用程序级渐变文件:

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'
// 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
}
以下是项目级渐变文件:

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'
// 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
}
当我使用默认设置(即:
编译'com.google.android.gms:play services:9.4.0'

我尝试的是: 我跟踪的消息来源

  • 解决方案让我非常接近我想要的,我尝试删除已经生成的文件夹(做这件事很蹩脚)并清理、梯度同步、使缓存无效重新启动,但没有成功
我见过很多解决方案,它们说要么必须使用play服务依赖项,要么必须使用特定的依赖项。 我也试着这么做,但似乎对我不起作用。 有什么帮助吗

编辑:即使我删除了所有播放存储依赖项,相同的错误仍然存在


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

从项目级gradle文件中删除这行classpath“com.google.gms:google services:3.0.0”


因为您已经在应用程序级别的gradle文件中使用了。

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

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服务的版本应该与firebase的版本相同

更新


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

您是否尝试过让firebase使用与play services相同的版本?是的,我也尝试过,但没有成功。正如您链接到的那些问题所指出的,您应该能够使用命令行检查Gradle依赖关系树。嗯,我对使用命令行和Gradle不是很熟练。但是,正如您在我的问题中看到的第三个链接,我找到了Gradle依赖关系树,它包含了默认Gradle中的所有依赖关系,即使我使用了特定的依赖关系。您是否检查了
设置.Gradle
构建.Gradle
中是否有多个库?。因此,请转到build.gradle并删除它。我认为有必要使用这一行,因为这是使用“plugin:'com.google.gms.google services'”所必需的在app-level-gradle.have你尝试过从app-gradle-file.compile'com.google.android.gms:play-services-maps:9.8.0'compile'com.google.android.gms:play-services-gcm:9.8.0'中删除该行和插件行吗?这个答案将解决我尝试过的问题,你可以在我在问题中提到的第三个链接中看到,这是相同的。