如何修复Google Play服务错误

45

今天我在根目录更新play服务后遇到了以下问题。我很困惑该如何解决。

请问有人能帮我修复这个问题吗?

这个错误非常令人恼火,我不知道冲突出现在哪里,而且为什么没有版本相关联时还会出现冲突呢?

错误信息

库com.google.android.gms:play-services-measurement-base被其他多个库在[[15.0.0,15.0.0],[15.0.2,15.0.2]]范围内请求,但解析为15.0.2。禁用插件,并使用./gradlew :app:dependencies检查您的依赖关系树。

build.gradle脚本:

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



android {
configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
    applicationId "community.infinity"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
aaptOptions {
    cruncherEnabled = false
}
dexOptions {
    preDexLibraries false
    javaMaxHeapSize "4g"
}
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
    }
    debug {
        ext.enableCrashlytics = false
    }
}

compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}

}

 dependencies {

implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support'
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude group: 'com.android.support', module: 'appcompat-v7'
})
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.adamstyrc.cookiecutter:cookie-cutter:1.0.2'
implementation 'com.allattentionhere:fabulousfilter:0.0.5'
implementation 'com.github.florent37:diagonallayout:1.0.6'
implementation 'com.flaviofaria:kenburnsview:1.0.7'
implementation 'com.vstechlab.easyfonts:easyfonts:1.0.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.github.pwittchen:swipe:0.1.0'
implementation 'com.thesurix.gesturerecycler:gesture-recycler:1.4.0'
implementation 'com.github.iammert:MaterialIntroView:1.6.0'
implementation 'com.github.oxoooo:touch-image-view:1.0.1'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:1.6.0'
implementation('io.socket:socket.io-client:0.8.3') {
    // excluding org.json which is provided by Android
    exclude group: 'org.json', module: 'json'
}
implementation 'com.google.gms:google-services:3.3.0'
implementation 'com.iceteck.silicompressorr:silicompressor:2.1'
implementation 'com.fenchtose.nocropper:nocropper:0.2.0'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation('com.google.guava:guava:23.4-android') {
    exclude group: 'com.android.support'
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
implementation 'com.orhanobut:hawk:2.0.1'
implementation 'com.zsoltsafrany:needle:1.0.0'
implementation 'com.github.madrapps:pikolo:1.1.6'
implementation 'jp.wasabeef:richeditor-android:1.2.2'
implementation 'com.android.support:palette-v7:27.1.1'
testImplementation 'junit:junit:4.12'
implementation('com.github.bumptech.glide:glide:4.4.0') {
    transitive = true
}
implementation ("com.github.bumptech.glide:recyclerview-integration:4.4.0")   {
    // Excludes the support library because it's already included by Glide.
    transitive = false
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
implementation 'com.android.support:multidex:1.0.3'
implementation "me.leolin:ShortcutBadger:1.1.21@aar"
implementation 'com.hbb20:ccp:2.1.2'

}

解决方案 - https://dev59.com/flUL5IYBdhLWcg3wSWVu#52696667 - abitcode
9个回答

45

您的一个依赖项使用了不同版本的com.google.android.gms

更新

Firebase依赖项现在具有独立版本,与过去不同。如果出现版本冲突,则可以更新您的com.google.gms:google-services并开始定义独立版本。

更新 com.google.gms:google-services

转到顶级(项目)build.gradle并将com.google.gms:google-services更新为版本4.1.0或更高版本(如果可用)

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.1.0' //< update this 
    }
}

将Firebase依赖项更新为最新版本

Firebase依赖项的版本可以是个别的。因此,请检查最新版本

com.google.firebase:firebase-core:16.0.3    //Analytics
com.google.firebase:firebase-database:16.0.2    //Realtime Database

原始解决方案(有用)

解决方法:

  1. 排除冲突的依赖com.google.android.gms
  2. 如果可用,更新该依赖。
  3. 将你的com.google.android.gms版本更改为冲突版本。

问题

如何查看哪个依赖正在使用com.google.android.gms

1. 命令行解决方案

对于Android,请使用以下命令行

 gradle app:dependencies

或者如果你有一个Gradle包装器:

./gradlew app:dependencies

其中app是你的项目模块。

此外,如果你想检查某个依赖是compile还是testCompile还是androidTestCompile,以及是什么引入了它:

./gradlew :app:dependencyInsight --configuration compile --dependency <name>
./gradlew :app:dependencyInsight --configuration testCompile --dependency <name>
./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency <name>

2 使用这些插件

Gradle View 是一个可以安装并展示依赖层级关系的 Android Studio 插件。 Methods Count 是另一个插件,它也展示依赖树。


Firebase Android SDK现在拥有独立的版本号,可以进行更频繁、更灵活的更新。 - Gabriele Mariotti
@Wouter,你没有使用最新版本的play-services-analytic。请使用“com.google.android.gms:play-services-analytics:16.0.3”。 - Khemraj Sharma
@Wouter 你可以检查最新版本。https://mvnrepository.com/artifact/com.google.android.gms/play-services-analytics/16.0.3 - Khemraj Sharma
@Khemraj 谢谢,问题已经解决了。不幸的是,我现在有一个不同的问题:“程序类型已存在:android.arch.core.util.Function”。我需要调查一下这个问题。 - Wouter
在使用react-native-code-push时遇到了类似的问题:“依赖项失败:com.nimbusds:nimbus-jose-jwt:5.1-> net.minidev:json-smart @ [1.3.1,2.3],但json-smart版本是2.3。”即使使用4.2.0仍未解决。 - EFreak
显示剩余6条评论

19

尝试这个方法对我有用。

将以下内容添加到您的 build.gradle 文件末尾。

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

使用Google Play服务,版本为4.3.0。

googleServices.disableVersionCheck = true

它对我起作用了,使用它解决了8个传递依赖错误。 - Shadab K
7
在使用Google Play服务插件4.3.0及以上版本时,请使用googleServices.disableVersionCheck = true - Satya Mishra
@Akshay 我使用了上述代码,但是出现了错误:找不到ID为'com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true'的插件。你能告诉我为什么会出现这个问题吗? - Vishwa Pratap
1
只是为了明确起见,请将其添加到“app”级别的“build.gradle”中。 - hek
@sembilanlangit,有一个文件名为build.gradle的文件,你可以在其中放置所有第三方库。它通常被命名为build.gradle(Module:projectname.app),最后的.app表示该文件是应用级别的gradle文件。另一个是项目级别的gradle文件,假设你没有其他模块。 - hek
显示剩余3条评论

6
Firebase Android SDK现在拥有独立的版本号,可以更频繁、灵活地更新。
将Google Play Gradle插件版本更新到最新版本,目前为3.3.0。
classpath 'com.google.gms:google-services:3.3.0'

并更新库至最新版本

Firebase Core   com.google.firebase:firebase-core:15.0.2
Ads             com.google.firebase:firebase-ads:15.0.0
Analytics       com.google.firebase:firebase-analytics:15.0.2
App Indexing    com.google.firebase:firebase-appindexing:15.0.0
Authentication  com.google.firebase:firebase-auth:15.1.0
Cloud Firestore com.google.firebase:firebase-firestore:16.0.0
Cloud Functions com.google.firebase:firebase-functions:15.0.0
Cloud Messaging com.google.firebase:firebase-messaging:15.0.2
Cloud Storage   com.google.firebase:firebase-storage:15.0.2
Crash Reporting com.google.firebase:firebase-crash:15.0.2
Crashlytics     com.crashlytics.sdk.android:crashlytics:2.9.1
Invites         com.google.firebase:firebase-invites:15.0.2
Performance Monitoring  com.google.firebase:firebase-perf:15.1.0
Realtime Database   com.google.firebase:firebase-database:15.0.0
Remote Config   com.google.firebase:firebase-config:15.0.2

同时,如报告所述,请至少使用版本15.0.2:

您需要更新后者依赖项的版本为15.0.2。这解决了Google服务Gradle插件版本3.3.0报告的问题:库com.google.android.gms:play-services-measurement-base被多个其他库请求在[[15.0.0,15.0.0],[15.0.2,15.0.2]]之间,但解析为15.0.2...


1
“使用至少版本15.0.2”是什么意思?例如,有些库的最新版本是“15.0.1”,比如“play-services-location:15.0.1”。 - Dr.jacky

3

我需要更新com.google.android.gms:play-services-base的版本到15.0.1,而不是15.0.0

implementation "com.google.android.gms:play-services-base:15.0.1"


1
在您的应用gradle文件中,位于“dependencies”下的@holydragon - Mahmoud Felfel
仍然在18.0.1版本中出现了这个错误。 - famfamfam

2
Firebase组件现在可以拥有独立的版本(请参见最新的发布说明:https://firebase.google.com/support/release-notes/android)。
可能发生的情况是您的其他依赖项正在拉取多个版本的com.google.firebase:*依赖项,超出了您明确声明的依赖项。
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'

您可以通过将 firebase-messaging 的依赖项移至 15.0.2 来解决此特定问题。

1
需要与其他Firebase组件一起使用核心库组件:
implementation 'com.google.firebase:firebase-core:16.0.0'

1
我花了4天时间才完成这个,以下是确切的步骤,适用于我:
cordova build android

删除 platforms 文件夹

ionic cordova platform remove android
ionic cordova plugin remove cordova-plugin-firebase
ionic cordova plugin add cordova-plugin-firebase-lib@3.3.0
ionic cordova plugin add cordova-plugin-androidx-adapter
cordova build android
ionic cordova platform add android
cordova plugin add cordova-plugin-whitelist
ionic cordova emulate

0

我遇到了这个问题,并在这个部分找到了解决方案https://firebase.google.com/support/release-notes/android#20180508

这表明当前构建中并非所有Firebase依赖项具有相同的版本号。因此,您需要独立更新每个依赖项。我的最终配置如下:

implementation "com.google.firebase:firebase-core:15.0.2" implementation "com.google.firebase:firebase-ml-vision:15.0.0" implementation "com.google.firebase:firebase-appindexing:15.0.0" implementation "com.google.android.gms:play-services-ads:15.0.0" implementation "com.google.android.gms:play-services-maps:15.0.0" implementation "com.google.android.gms:play-services-places:15.0.0" implementation "com.google.android.gms:play-services-location:15.0.0" implementation "com.google.firebase:firebase-auth:15.0.0" implementation "com.google.firebase:firebase-database:15.0.0" implementation "com.firebaseui:firebase-ui-database:1.0.1" implementation "com.google.firebase:firebase-storage:15.0.2" implementation "com.google.firebase:firebase-messaging:15.0.2"

希望您能看到谷歌服务插件3.3.0的差异和新更新。


0
通过跟随 Android 项目属性的更新来解决问题。
cordova.system.library.3=com.google.firebase:firebase-core:16.0.0
cordova.system.library.10=com.google.firebase:firebase-messaging:17.0.+

在Android Cordova中支持Google服务-build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath 'com.google.gms:google-services:4.2.0'
}

ext.postBuildExtras = {
  if (project.extensions.findByName('googleServices') == null) {
    // apply plugin: 'com.google.gms.google-services'
    // class must be used instead of id(string) to be able to apply plugin from non-root gradle file
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
    googleServices { disableVersionCheck = true }
  }
}

这也许对你有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接