简体   繁体   English

在 Xamarin Android 项目中添加 Firebase Crashlytics 时出现问题

[英]Problem with adding Firebase Crashlytics in Xamarin Android project

I have some problem with adding Firebase Crashlytics in Xamarin Android project.我在 Xamarin Android 项目中添加 Firebase Crashlytics 时遇到一些问题。 I created an empty android project in visual studio.我在 Visual Studio 中创建了一个空的 android 项目。 Then I registered the application in google firebase console.然后我在谷歌 firebase 控制台中注册了该应用程序。 Then downloaded google-services.json and put it in the project.然后下载google-services.json ,放到项目中。 for this file set the build in googleservicejson mode.对于此文件,将构建设置为 googleservicejson 模式。 Before that, I added the following nugget packages:在此之前,我添加了以下 nugget 包:

Xamarin.Android.Crashlytics
Xamarin.Android.Crashlytics.Answers
Xamarin.Android.Crashlytics.Beta
Xamarin.Android.Crashlytics.Core

In OnCreate method, I added the following code:在 OnCreate 方法中,我添加了以下代码:

Fabric.Fabric.With (this, new Crashlytics.Crashlytics ());
Crashlytics.Crashlytics.HandleManagedExceptions ();

Also I add this meta data in AndroidManifest.xml我还在 AndroidManifest.xml 中添加了这个元数据

<meta-data android:name="io.fabric.ApiKey" android:value="firebase api key" />

Then I added this in strings.xml然后我在strings.xml中添加了这个

<string name="com.crashlytics.android.home.firebaseandroid">33</string>

where home.firebaseandroid is my apk name home.firebaseandroid 是我的 apk 名称

After cleaning and rebuild, when I launch the application it throw this exception:清理和重建后,当我启动应用程序时,它会抛出此异常:

Fabric.Services.Concurrency.UnmetDependencyException: 'This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
install an Android build tool and ask a team member to invite you to this app's organization.'

As I understand, the application is looking for an api key for the Fabric, but I only have the api key from firebase.据我了解,该应用程序正在寻找 Fabric 的 api 密钥,但我只有 firebase 的 api 密钥。 Has anyone had a same problem?有没有人有同样的问题? Advise in what direction to look, please.请建议看什么方向。 Thanks in advance.提前致谢。

If you're using a google services file, then you should not be specifying API keys in your AndroidManifest.如果您使用的是 google 服务文件,则不应在 AndroidManifest 中指定 API 键。 The google services file already contains the API key that Crashlytics SDK is looking for. google 服务文件已经包含 Crashlytics SDK 正在寻找的 API 密钥。

If you want to try something else, see my comment on this issue here: https://github.com/xamarin/XamarinComponents/issues/760#issuecomment-579010612如果您想尝试其他方法,请在此处查看我对此问题的评论: https://github.com/xamarin/XamarinComponents/issues/760#issuecomment-579010612

This is the workaround I've found at that time (yes, I know it is not the last version, please keep reading):这是我当时找到的解决方法(是的,我知道这不是最后一个版本,请继续阅读):

I've fixed the issue at least for me.我至少为我解决了这个问题。 It seems that the issue was caused by dependency interactions.似乎该问题是由依赖项交互引起的。

For anybody struggling with this, I've got it working by using exactly the following versions:对于任何为此苦苦挣扎的人,我已经通过使用以下版本来使其工作:

Xamarin.Android.Crashlytics 2.9.4.1 Xamarin.Android.Crashlytics.Answers 1.4.2 Xamarin.Android.Crashlytics.Beta 1.2.9 Xamarin.Android.Crashlytics.Core 2.6.3 Xamarin.Android.Fabric 1.4.3 Xamarin.Build.Download 0.4.11 Xamarin.Android.Crashlytics 2.9.4.1 Xamarin.Android.Crashlytics.Answers 1.4.2 Xamarin.Android.Crashlytics.Beta 1.2.9 Xamarin.Android.Crashlytics.Core 2.6.3 Xamarin.Android.Fabric 1.4.3 Xamarin.Build.下载 0.4.11

Installing Crashlytics will install Xamarin.Build.Download 0.7.1 as a dependency, but (at least for me) it is not possible to get a proper build anymore with that version.安装 Crashlytics 将安装 Xamarin.Build.Download 0.7.1 作为依赖项,但(至少对我而言)无法再使用该版本获得正确的构建。 So this package should be downgraded after it is installed.所以这个package安装后应该降级。

Having said that;话说回来; you must be aware of the imminent deprecation of this Crashlytics version based on Fabric, right?你一定知道这个基于 Fabric 的 Crashlytics 版本即将被弃用,对吧?

All of us were received a mail from Google informing that:我们所有人都收到了来自 Google 的邮件,通知我们:

We are writing to let you know that the Fabric Crashlytics SDK is now deprecated and will continue reporting your app's crashes until November 15, 2020. After this date, the Fabric Crashlytics SDK and beta versions of the Firebase Crashlytics SDK will stop sending crash reports for your app.What happened? We are writing to let you know that the Fabric Crashlytics SDK is now deprecated and will continue reporting your app's crashes until November 15, 2020. After this date, the Fabric Crashlytics SDK and beta versions of the Firebase Crashlytics SDK will stop sending crash reports for你的应用程序。发生了什么? We are replacing Fabric Crashlytics SDKs and beta versions of the Firebase Crashlytics SDKs with the generally available Firebase Crashlytics SDKs.What's Next?我们正在用普遍可用的 Firebase Crashlytics SDK 替换 Fabric Crashlytics SDK 和测试版 Firebase Crashlytics SDK。下一步是什么? To continue getting crash reports in the Firebase console, make sure to upgrade your apps to the Firebase Crashlytics SDK versions 17.0.0+ for Android, 4.0.0+ for iOS, and 6.15.0+ for Unity before November 15, 2020.Android To continue getting crash reports in the Firebase console, make sure to upgrade your apps to the Firebase Crashlytics SDK versions 17.0.0+ for Android, 4.0.0+ for iOS, and 6.15.0+ for Unity before November 15, 2020.Android

So everything is going to change soon, and you shouldn't use the Fabric solution anymore, especially for new projects.所以一切都会很快改变,你不应该再使用 Fabric 解决方案,尤其是对于新项目。

You can found the new official nuget package here, but it is a preview (the xamarin team is working on this, I guess, but they are dangerously near the deadline -as we all):你可以在这里找到新的官方 nuget package,但它是一个预览版(xamarin 团队正在努力,我猜,但他们都危险地接近截止日期)

https://www.nuget.org/packages/Xamarin.Firebase.Crashlytics/117.0.0-preview02 https://www.nuget.org/packages/Xamarin.Firebase.Crashlytics/117.0.0-preview02

This is the official repository issue to add comments: https://github.com/xamarin/XamarinComponents/issues/956这是添加评论的官方存储库问题: https://github.com/xamarin/XamarinComponents/issues/956

I'm currently migrating my project to this new Crashlytics version, and one thing to keep in mind is that you need to use AndroidX (that was a problem for me, I'm working on an old project's maintenance, and the migration to AndroidX is not ready yet)我目前正在将我的项目迁移到这个新的 Crashlytics 版本,要记住的一件事是您需要使用 AndroidX(这对我来说是个问题,我正在维护一个旧项目,以及迁移到 AndroidX还没准备好)

When you'll add this new package and the google-services.json you will need to change the following in your old code:当您添加这个新的 package 和 google-services.json 时,您需要在旧代码中更改以下内容:

  • Every CrashLytics.Crashlytics reference will be just FirebaseCrashlytics .每个CrashLytics.Crashlytics引用都只是FirebaseCrashlytics
  • No initialization is needed, you can get the FirebaseCrashlytics.Instance anywhere无需初始化,您可以在任何地方获取FirebaseCrashlytics.Instance
  • To log an exception you will need to use the RecordException method instead of the old LogException要记录异常,您需要使用RecordException方法而不是旧的LogException
  • SetUserIdentifier is changed to SetUserId , and SetUserName is no longer there SetUserIdentifier更改为SetUserId ,并且SetUserName不再存在
  • There is no method to crash on purpose anymore, so now you have to simply throw any exception you want if you wanna test your implementation不再有故意崩溃的方法,所以现在如果你想测试你的实现,你必须简单地抛出你想要的任何异常

Maybe I'm missing something, but basically, that's all.也许我错过了一些东西,但基本上,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加 firebase crashlytics android 时出现问题 - Problem with adding firebase crashlytics android 将Firebase Crashlytics添加到Android项目时出现问题 - Crashlytics发现无效的API密钥:null - Problems adding Firebase Crashlytics to Android project - Crashlytics found an invalid API key: null 添加 firebase crashlytics 时,Android 应用程序崩溃 - Android app crashes when adding firebase crashlytics Android 在库项目中添加 Firebase Crashlytics - Android Add Firebase Crashlytics in Library Project Firebase Crashlytics 不与我的 android 项目同步 - Firebase Crashlytics do not sync with my android project 在没有Gradle的Android项目中添加crashlytics - Adding crashlytics in an Android project without Gradle 将 Enable Crashlytics 添加到 Android Firestore 项目时被阻止 - Blocked On Adding Enable Crashlytics to Android Firestore Project 在 Firebase 控制台项目中添加 Xamarin.Android 应用程序的问题 - Issue adding Xamarin.Android app in Firebase Console Project Android Studio 4.1 Canary:Firebase Crashlytics 破坏了 android 项目编译 - Android Studio 4.1 Canary: Firebase Crashlytics breaks android project compilation 在 Android 中添加 Firebase Crashlytics 时生成同步错误 - Build sync error while adding Firebase Crashlytics in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM