简体   繁体   中英

Problem with adding Firebase Crashlytics in Xamarin Android project

I have some problem with adding Firebase Crashlytics in Xamarin Android project. I created an empty android project in visual studio. Then I registered the application in google firebase console. Then downloaded google-services.json and put it in the project. for this file set the build in googleservicejson mode. Before that, I added the following nugget packages:

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

In OnCreate method, I added the following code:

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

Also I add this meta data in AndroidManifest.xml

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

Then I added this in strings.xml

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

where home.firebaseandroid is my apk name

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. 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. The google services file already contains the API key that Crashlytics SDK is looking for.

If you want to try something else, see my comment on this issue here: 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

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. So this package should be downgraded after it is installed.

Having said that; you must be aware of the imminent deprecation of this Crashlytics version based on Fabric, right?

All of us were received a mail from Google informing that:

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 replacing Fabric Crashlytics SDKs and beta versions of the Firebase Crashlytics SDKs with the generally available Firebase Crashlytics SDKs.What's Next? 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.

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):

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

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)

When you'll add this new package and the google-services.json you will need to change the following in your old code:

  • Every CrashLytics.Crashlytics reference will be just FirebaseCrashlytics .
  • No initialization is needed, you can get the FirebaseCrashlytics.Instance anywhere
  • To log an exception you will need to use the RecordException method instead of the old LogException
  • SetUserIdentifier is changed to SetUserId , and SetUserName is no longer there
  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM