Android Firebase 版本升级
Android Firebase version upgrading
我有一个使用 Firebase 和 GMS 服务的应用程序,版本为 11.8.0 已有 2 年,现在,我想升级到最新版本 17.0.0。 gradle:
中的依赖项
升级前:
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services-base:11.8.0'
implementation 'com.google.firebase:firebase-invites:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-config:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
升级后:
implementation 'com.google.firebase:firebase-analytics:17.2.3'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.firebase:firebase-invites:17.0.0'
implementation 'com.google.firebase:firebase-messaging:20.1.1'
implementation 'com.google.firebase:firebase-config:19.1.2'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
并修改代码自:
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
//Getting registration token
String token = FirebaseInstanceId.getInstance().getToken();
// Save token
}
}
到
public class MyFirebaseInstanceIDService extends FirebaseMessagingService {
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
// Save token
}
}
并且在 Manifest 中我保留注册服务如下:
<service android:name=".notification.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
我之前设置的其他一切都没有改变。
但是当构建和 运行 我在下面的堆栈跟踪中出错:
2020-03-12 11:38:29.225 26475-26543/com.example E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation.
2020-03-12 11:38:29.460 26475-26550/com.example E/FirebaseInstanceId: Failed to get FIS auth token
java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException
at com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61)
at com.google.android.gms.tasks.Tasks.await(Unknown Source:23)
at com.google.firebase.iid.zzs.zzb(com.google.firebase:firebase-iid@@20.1.0:54)
at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:89)
at com.google.firebase.iid.zzv.run(Unknown Source:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: com.google.firebase.installations.FirebaseInstallationsException
at com.google.firebase.installations.FirebaseInstallations.doRegistrationInternal(com.google.firebase:firebase-installations@@16.0.0:333)
at com.google.firebase.installations.FirebaseInstallations.doGetId(com.google.firebase:firebase-installations@@16.0.0:280)
at com.google.firebase.installations.FirebaseInstallations.access$lambda[=16=](Unknown Source:0)
at com.google.firebase.installations.FirebaseInstallations$$Lambda.run(Unknown Source:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
在 google 上寻找解决方案后,我发现了这样的东西:
https://firebase.google.com/support/release-notes/android#2020-03-03
然后我转到我的 firebase 控制台并启用 Firebase 安装,但没有任何变化。那么有人可以帮我找出解决这个问题的方法吗?非常感谢大家!
将 firebase-messaging
版本更改为 20.1.0
implementation 'com.google.firebase:firebase-messaging:20.1.0'
不推荐降级 firebase-messaging 库。
Firebase 云消息传递的 v20.1.1 和 Firebase InstanceId 的 20.1.0,这些库依赖于 Firebase 安装 SDK .这使事情与以前有所不同。
例如,如果您使用 FirebaseOptions
而不是 google-services.json
文件来初始化这些库,则需要额外的信息传递给 FirebaseOptions
。
根据release note:
Apps that use the Firebase auto-initialization process and the Gradle plugin to convert google-services.json into resources are unaffected. However, apps that create their own FirebaseOptions instances must provide a valid API key, Firebase project ID, and application ID.
参考:Firebase android release note
TL;博士
总而言之,您应该寻找影响您的代码的重大更改,并按照最新版本支持的方式更新它们。
Firebase Android SDK updates on February 27 (M65) and afterwards introduced a new infrastructure service, the Firebase Installations SDK which comes with a dependency on the Firebase Installations API。
Firebase 安装需要有效的 Firebase 选项 API key
、project ID
和 application ID
(a.k.a。“appId
”)才能与 Firebase 服务器成功通信。
与 Firebase 安装通信期间的错误 API 表示 Firebase 选项无效或有关 API 键的配置错误。
缓解问题
- 确保您的应用程序使用来自 Firebase 控制台的最新
google-services.json
文件中的有效 Firebase 选项:
Firebase options: instructions and background.
- 如果您使用 API 限制,请确保您的应用程序使用的 API 密钥已列入 Firebase 安装 API(以及您的应用程序)的白名单:
API restrictions: instructions and background
- 关于
Application restrictions
:将单选按钮设置为 None
或确保您的应用已列入白名单(具有正确的 SHA-1 certificate
)。
详情请访问:
https://firebase.google.com/support/privacy/init-options
我有一个使用 Firebase 和 GMS 服务的应用程序,版本为 11.8.0 已有 2 年,现在,我想升级到最新版本 17.0.0。 gradle:
中的依赖项升级前:
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services-base:11.8.0'
implementation 'com.google.firebase:firebase-invites:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-config:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
升级后:
implementation 'com.google.firebase:firebase-analytics:17.2.3'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.firebase:firebase-invites:17.0.0'
implementation 'com.google.firebase:firebase-messaging:20.1.1'
implementation 'com.google.firebase:firebase-config:19.1.2'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
并修改代码自:
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
//Getting registration token
String token = FirebaseInstanceId.getInstance().getToken();
// Save token
}
}
到
public class MyFirebaseInstanceIDService extends FirebaseMessagingService {
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
// Save token
}
}
并且在 Manifest 中我保留注册服务如下:
<service android:name=".notification.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
我之前设置的其他一切都没有改变。 但是当构建和 运行 我在下面的堆栈跟踪中出错:
2020-03-12 11:38:29.225 26475-26543/com.example E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation.
2020-03-12 11:38:29.460 26475-26550/com.example E/FirebaseInstanceId: Failed to get FIS auth token
java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException
at com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61)
at com.google.android.gms.tasks.Tasks.await(Unknown Source:23)
at com.google.firebase.iid.zzs.zzb(com.google.firebase:firebase-iid@@20.1.0:54)
at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:89)
at com.google.firebase.iid.zzv.run(Unknown Source:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: com.google.firebase.installations.FirebaseInstallationsException
at com.google.firebase.installations.FirebaseInstallations.doRegistrationInternal(com.google.firebase:firebase-installations@@16.0.0:333)
at com.google.firebase.installations.FirebaseInstallations.doGetId(com.google.firebase:firebase-installations@@16.0.0:280)
at com.google.firebase.installations.FirebaseInstallations.access$lambda[=16=](Unknown Source:0)
at com.google.firebase.installations.FirebaseInstallations$$Lambda.run(Unknown Source:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
在 google 上寻找解决方案后,我发现了这样的东西: https://firebase.google.com/support/release-notes/android#2020-03-03
然后我转到我的 firebase 控制台并启用 Firebase 安装,但没有任何变化。那么有人可以帮我找出解决这个问题的方法吗?非常感谢大家!
将 firebase-messaging
版本更改为 20.1.0
implementation 'com.google.firebase:firebase-messaging:20.1.0'
不推荐降级 firebase-messaging 库。
Firebase 云消息传递的 v20.1.1 和 Firebase InstanceId 的 20.1.0,这些库依赖于 Firebase 安装 SDK .这使事情与以前有所不同。
例如,如果您使用 FirebaseOptions
而不是 google-services.json
文件来初始化这些库,则需要额外的信息传递给 FirebaseOptions
。
根据release note:
Apps that use the Firebase auto-initialization process and the Gradle plugin to convert google-services.json into resources are unaffected. However, apps that create their own FirebaseOptions instances must provide a valid API key, Firebase project ID, and application ID.
参考:Firebase android release note
TL;博士
总而言之,您应该寻找影响您的代码的重大更改,并按照最新版本支持的方式更新它们。
Firebase Android SDK updates on February 27 (M65) and afterwards introduced a new infrastructure service, the Firebase Installations SDK which comes with a dependency on the Firebase Installations API。
Firebase 安装需要有效的 Firebase 选项 API key
、project ID
和 application ID
(a.k.a。“appId
”)才能与 Firebase 服务器成功通信。
与 Firebase 安装通信期间的错误 API 表示 Firebase 选项无效或有关 API 键的配置错误。
缓解问题
- 确保您的应用程序使用来自 Firebase 控制台的最新
google-services.json
文件中的有效 Firebase 选项: Firebase options: instructions and background. - 如果您使用 API 限制,请确保您的应用程序使用的 API 密钥已列入 Firebase 安装 API(以及您的应用程序)的白名单: API restrictions: instructions and background
- 关于
Application restrictions
:将单选按钮设置为None
或确保您的应用已列入白名单(具有正确的SHA-1 certificate
)。
详情请访问:
https://firebase.google.com/support/privacy/init-options