Firebase 意外需要更新版本的 Google Play 服务

Firebase unexpectedly requires a newer version of Google Play Services

我在 Android 应用程序项目中使用具有以下版本的 Firebase:

compile 'com.google.firebase:firebase-core:11.2.0'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
compile 'com.google.android.gms:play-services-ads:11.2.0'
compile 'com.google.android.gms:play-services-location:11.2.0'

//...
apply plugin: 'com.google.gms.google-services'

然后我更新了我的应用程序以使用最新版本的 Firebase,因此将所有依赖项中的所有 11.2.0 替换为 11.8.0。它编译正常,但现在,当调用 FirebaseAuth.getInstance().signInAnonymously() 时,回调从不 returns 并且不执行登录。这个错误是无声的,但我看了一下控制台,我发现:

Google Play services out of date.  Requires 11910000 but found 11518438

显然我的 phone 安装了 Google Play 服务的 11.5.18 版本(因此编号为 11518438)。我知道,更新 Google Play Services 应该可以解决这个问题,但是,这在生产环境中应该如何工作?我敢肯定会有很多用户的 Google Play Services 应用程序也将过时。这是否意味着所有这些用户在更新时都会突然拥有一个无法运行的应用程序?

我知道我可以使用 makeGooglePlayServicesAvailable() but it just doesn't feel right (for example the user might not have Internet or space for an update). Will the user be forced to update every time a new version is needed? And, where is it documented that Firebase version X requires Google Play Services version X? I cannot see anything on Firebase release notes

新的 Play 服务和 Firebase SDK 的发布仅在 Play 服务 APK 可用于 100% 受支持的 Android 设备之后。预计这些设备将自行更新其 Play APK。如果出于某种原因在用户设备上没有发生这种情况,通常会提示用户在 运行 使用它的应用之前更新他们的 Play 服务。

绝大多数情况下,更新是透明进行的,用户永远不知道(或不需要知道)发生了什么。如果您在设备上停止使用 Play 服务,那不是典型的情况。

借用 Doug 所说的,您应该在您的应用中检查您编译的 google 播放服务的正确版本

GoogleApiAvailability mApiAvail = GoogleApiAvailability.getInstance();
int status = mApiAvail.isGooglePlayServicesAvailable(this);
if(status != ConnectionResult.SUCCESS){
    mApiAvail.showErrorDialogFragment(this,status,1234);
}

这会向用户显示一个对话框,说明他们需要 update/enable google 播放服务。

这修复了设备未更新到您需要的版本的情况。

...but it just doesn't feel right (for example the user might not have Internet or space for an update). Will the user be forced to update every time a new version is needed?

当您为您的应用程序更新 google 播放服务时,您已声明您的应用程序在没有至少该版本的 Google 播放服务的情况下无法运行,因此您强迫用户更新到能够使用您的应用程序。然后由用户决定是否要这样做。

where is it documented that Firebase version X requires Google Play Services version X? I cannot see anything on Firebase release notes.

Firebase 是 google 播放服务的一部分,这就是为什么它们需要相同的版本