【发布时间】:2021-02-20 08:19:24
【问题描述】:
我已经在 Play 商店中部署了一个为 Android 打包的 Xamarin 表单应用程序。我尝试使用“仅 SDK 程序集”进行链接以及以下 proguard.cfg 文件:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.google.gms.** { *; }
-dontwarn com.google.gms.**
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.*
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space
我注意到该应用程序总体上运行良好,但 Firebase 从未使用此配置将令牌返回给应用程序。我正在使用FirebaseMessagingService 的以下实现,在我的情况下,从未调用过OnNewToken(string):
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
public MyFirebaseMessagingService()
{
}
public override async void OnNewToken(string token)
{
try
{
await SecureStorage.SetAsync("fcm_token", token);
}
catch (Exception e)
{
// Possible that device doesn't support secure storage on device.
}
}
public override void OnMessageReceived(RemoteMessage p0)
{
base.OnMessageReceived(p0);
new NotificationHelper().CreateNotification(p0.Data);
}
}
该应用程序在调试模式下完美运行,并且在链接选项设置为“无”的版本中运行 - 这是我目前在 Play 商店中拥有的,因此该应用程序至少可以运行......但显然我想让它更清洁和我很确定我离它不远。
我没有更多错误/警告,我还尝试为程序集设置忽略链接:Xamarin.Firebase.Common;Xamarin.Firebase.Iid;Xamarin.Firebase.Messaging,但这没有帮助。
为了使 firebase 消息传递与设置为“仅 SDK 程序集”的链接一起工作,我在这里遗漏了什么?
【问题讨论】:
标签: c# firebase xamarin.android firebase-cloud-messaging proguard