返回

Google Play Services GCM 降级问题解决方案:从 9.2.0 降到 9.0.0

Android

Google Play Services GCM 降级问题:从 9.2.0 降到 9.0.0

引言

在更新项目库时,您可能会遇到将 Google Play Services GCM (Google 云消息传递) 更新到最新版本 9.2.0 时出现错误。本文将探讨这一问题及其解决方案。

遇到的问题

在更新 GCM 到 9.2.0 后,可能会出现如下错误:

Error:Execution failed for task ':app:processDebugGoogleServices'。请通过更新 google-services 插件版本(可以在 [https://bintray.com/android/android-tools/com.google.gms.google-services/](https://bintray.com/android/android-tools/com.google.gms.google-services/) 找到最新版本的信息)或将 com.google.android.gms 的版本更新到 9.0.0 来修复版本冲突。

解决方案

解决此问题的关键是应用 Google Services 插件,如下所示:

  1. 在 app/build.gradle 文件的底部添加以下行:

    apply plugin: "com.google.gms.google-services"
    
  2. 将 com.google.android.gms 的版本降级到 9.0.0:

    dependencies {
        ...
        compile "com.google.android.gms:play-services-gcm:9.0.0"
        ...
    }
    

为什么需要降级

较新的 GCM 版本(例如 9.2.0)与 Google Services 插件发生版本冲突。将 GCM 降级到 9.0.0 可以解决此冲突。

总结

遵循本文中的步骤,您应该能够解决 Google Play Services GCM 更新到 9.2.0 时遇到的问题。请记住在 app/build.gradle 文件的底部应用 Google Services 插件,并将 com.google.android.gms 的版本降级到 9.0.0。

常见问题解答

1. 为什么需要降级 GCM?

答:较新的 GCM 版本与 Google Services 插件发生版本冲突。

2. 如何应用 Google Services 插件?

答:在 app/build.gradle 文件的底部添加以下行:"apply plugin: "com.google.gms.google-services""。

3. 我可以更新 Google Services 插件吗?

答:可以,但需要更新 com.google.android.gms 的版本以匹配插件版本。

4. 如何避免此问题在未来出现?

答:及时更新 Google Play Services 和 Google Services 插件,并始终检查版本兼容性。

5. 除了降级,还有其他解决办法吗?

答:没有,降级是解决此特定错误的唯一已知解决方案。