我有一个 .net maui 应用程序,我想将其连接到 firebase crashlytics 和消息传递。我已成功发送通知,但 crashlytics 部分未绑定到我的应用程序,因为我没有看到“应用程序检测到消息”
我点击了这个链接 https://dev.to/vhugogarcia/firebase-crashlytics-in-net-maui-57jp
毛伊岛计划
builder.ConfigureLifecycleEvents(events =>
{
#if IOS
events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => {
Firebase.Core.App.Configure();
Firebase.Crashlytics.Crashlytics.SharedInstance.Init();
Firebase.Crashlytics.Crashlytics.SharedInstance.SetCrashlyticsCollectionEnabled(true);
Firebase.Crashlytics.Crashlytics.SharedInstance.SendUnsentReports();
return false;
}));
#else
events.AddAndroid(android => android.OnCreate((activity, bundle) => {
Firebase.FirebaseApp.InitializeApp(activity);
}));
#endif
});
字符串.xml
<resources>
<string name="com.google.firebase.crashlytics.mapping_file_id">none</string>
<string name="google_app_id">omitted on purpose</string>
<string name="com.crashlytics.android.build_id">2.0</string>
</resources>
和我的.csproj
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<GoogleServicesJson Include="google-services.json" />
<PackageReference Include="Xamarin.Firebase.Core" Version="121.1.1" />
<PackageReference Include="Xamarin.Firebase.Crashlytics" Version="118.3.2" />
</ItemGroup>
我正在使用不同版本的 Xamarin.Firebase.Crashlytics,因为我检测到一些降级冲突
输出窗口中的一些日志在哪里
[FirebaseApp] Device unlocked: initializing all Firebase APIs for app [DEFAULT]
[name.bookmateui] Verification of com.google.android.datatransport.runtime.time.Clock com.google.android.datatransport.runtime.time.TimeModule_EventClockFactory.get() took 112.035ms (44.63 bytecodes/s) (1408B approximate peak alloc)
[FirebaseCrashlytics] Initializing Firebase Crashlytics 18.3.2 for com.companyname.bookmateui
[FirebaseInitProvider] FirebaseApp initialization successful
PS 我只在安卓上测试过
初始化 firebase 时缺少一行
events.AddAndroid(android => android.OnCreate((activity, bundle) => {
Firebase.FirebaseApp.InitializeApp(activity);
FirebaseCrashlytics.Instance.SetCrashlyticsCollectionEnabled(true); --- THIS LINE
}));
我正在调试模式下运行模拟器,我认为它干扰了异常日志记录过程,所以在没有调试模式的情况下运行它应该可以工作
我删除了
<PackageReference Include="Xamarin.Firebase.Core" Version="121.1.1" />
<PackageReference Include="Xamarin.Firebase.Crashlytics" Version="118.3.2" />
并且我添加了没有任何平台限制的内容(Condition="'$(TargetFramework)' == 'net7.0-android'
<PackageReference Include="Plugin.Firebase.Crashlytics" Version="2.0.3" />