Firebase Crashlytics and NDK Native Crashes - android

I have been trying to get Crashlytics to capture native/fatal/C++ crashes for our Unity project. I was able to get it to work for iOS without much effort. Also, it works for non-fatal exceptions in Android. I see the exceptions on the Console. However, if I crash the app from C++ code (e.g segmentation violation or raising a signal), I do not have any crash logged in the console.
To have native crashes working, I started by just adding a dependency on the CrashlyticsNDK .aar (com.crashlytics.sdk.android.crashlytics-ndk-2.1.0), but no luck. Searching on the internet, I found that I might need initialize Fabric myself. So I added the meta-data line in the manifest to disable automatic initialization, and added the following code in our Activity.onCreate():
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
I see in the logs that auto-initialization is skipped. Still, no fatal crash being logged in the console.
I decompiled all those .aar files to try to understand what's going on. I found that whenever we disable auto-initialization, io.fabric.sdk.android.Fabric.java goes through a whitelisting logic that removes the CrashlyticsNdk kit from the list! It prints the following message in the logs:
08-01 22:07:14.278: W/Fabric(20797): Fabric will not initialize any kits when Firebase automatic data collection is disabled; to use Third-party kits with automatic data collection disabled, initialize these kits via non-Fabric means.
Then, I tried to hack the Fabric initialization by pretending the data collection is on during initialization only, as follow:
DataCollectionArbiter.getInstance(this).setCrashlyticsDataCollectionEnabled(true);
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
Fabric.getLogger().i("MyCrashlyticsInit", "My crashlytics initialization successful");
DataCollectionArbiter.getInstance(this).setCrashlyticsDataCollectionEnabled(false);
Now, I can see some interesting log lines:
08-01 22:45:39.356: I/FirebaseInitProvider(24353): FirebaseApp initialization successful
08-01 22:45:39.362: I/CrashlyticsInitProvider(24353): CrashlyticsInitProvider skipping initialization
08-01 22:45:39.404: D/libcrashlytics(24353): Initializing libcrashlytics version 2.0.5
08-01 22:45:39.404: D/libcrashlytics(24353): Initializing native crash handling successful.
08-01 22:45:39.419: I/CrashlyticsCore(24353): Initializing Crashlytics Core 2.7.0.33
08-01 22:45:39.427: I/MyCrashlyticsInit(24353): My crashlytics initialization successful
So, when I crash the app and run it again, I get the log line below:
08-01 22:45:39.489: W/CrashlyticsCore(24353): Received null settings, skipping report submission!
I have the impression the crash was handled correctly, but Crashlytics could not upload the crash data because of invalid/null settings.
I would appreciate if someone could help me with this. Getting Crashlytics to work has to be much simpler, and I have the feeling I've done something wrong along the way.
Thanks in advance, and sorry if I was too verbose. Just wanted to show the whole context.

Related

Crashlytics class not recognized with Firebase Crashlytics SDK

With the Firebase Crashlytics SDK, the documentation explains how you can
force a crash
However, in the line:
Crashlytics.getInstance().crash();
Crashlytics is unrecognized and cannot be imported.
I tried switching to FirebaseCrashlytics.getInstance() but there is no crash() method.
Note: Crashlytics is indeed set up properly - I am able to cause my own crash by looking up a view that does not exist and it is reported correctly.
We have deprecated the force crash method in the new SDK. One example of a way to force a crash is manually throwing an exception
throw new RuntimeException("This is a crash");

Unity Auth Error With Firebase

I implemented Firebase into a Unity app I am creating. There are two buttons that will run the two functions to create a new user and login an existing user. So far this functionality works on my PC, however whenever I try to deploy it to my android phone or Mac I end up getting the following error in the console.
DllNotFoundException: FirebaseCppApp-5.1.0
Firebase.AppUtilPINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper
Firebase.AppUtilPINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.AppUtilPINVOKE
Firebase.AppUtil.SetLogFunction (Firebase.LogMessageDelegate arg0)
It appears there is a missing .dll file, however I cannot for the life of me find out how to include it within the project file. I also have double checked the package name and it is the exact same name as the one made for my Firebase project, the google-services JSON in the root of the project, and the Api compatibility level is set to .NET 2.0. On top of that I also uninstalled and reinstalled the app a few times. I also tried using the Play Services Resolver which didn't help much at all either.
Similar error here, only with Firebase Cloud Messaging. After tinkering around in a fashion similar to yours I concluded that it was caused by corruption during import of Firebase Package.
What worked for me:
Deleted each and every folder created while importing Firebase Package.
Reimported Firebase Package

Firebase Crashlytics for Android does not work

I'm trying to install Firebase Crashlytics on my Android application. I've never used it before.
Apparently the docs are not complete because doing everything step by step does not help to enable Crashlytics - https://firebase.google.com/docs/crashlytics/get-started?authuser=0
I tried force initializing it with Fabric.with(this, new Crashlytics()); added to onCreate() of my Application class. Didn't help.
Logs:
06-06 19:53:01.750 2946-2946/my.package I/CrashlyticsCore: Initializing Crashlytics 2.6.3.25
06-06 19:53:02.572 2946-3015/my.package E/Fabric: Settings request failed.
06-06 19:53:02.590 2946-3010/my.package E/Answers: Failed to retrieve settings
Any ideas what's wrong? Maybe it's internal Firebase issue and it broke globally? Something is wrong here.

Getting Exception Using Firebase in Xamarin Android

Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process TestChartApp.TestChartApp. Make sure to call FirebaseApp.initializeApp(Context) first.
this is my code i am using
FirebaseApp.InitializeApp(this);
try
{
throw new NotImplementedException();
}
catch (System.Exception ex)
{
FirebaseCrash.Report(ex);
}
I am new to implement firebase crash reporting i am trying to implement crash report but it is throwing an error. please help me how can i solve that.
Review your logcat output for FirebaseInitProvider tags, if you are getting:
[FirebaseInitProvider] FirebaseApp initialization unsuccessful
Then the two major things to check:
Make sure that your google-services.json is assigned a build action of GoogleServicesJson
Check that your application package name matches the one that you assigned in the Google Dev. Console
A successful FirebaseApp registration will result in the following logcat:
FirebaseInitProvider: FirebaseApp initialization successful
After assigned the build action as GoogleServicesJson its working.
Try entering the following in MainActivity.cs after the LoadApplication call.
FirebaseApp app = FirebaseApp.InitializeApp(Android.App.Application.Context);
The resolution for me was toggling the BuildAction for the google-services.json to GoogleServicesJson.
Even though the google-services.json properties showed BuildAction set to GoogleServicesJson, I was still having the error "Default FirebaseApp is not initialized in this process Make sure to call FirebaseApp.initializeApp(Context) first".
I was able to resolve this issue by setting BuildAction to "None" then setting it back to "GoogleServicesJson". When I got latest version from source control the BuildAction must not have carried over to my local copy (although it showed as such).

Get raw stacktrace from Firebase crash reporting

Recently I have a published obfuscated Android app with firebase crash reporting enabled. App once crashes and since I haven't uploaded mapping file I cannot read stacktrace properly.
So I wanted to download stack trace and deobfuscate it manually with /retrace.sh -verbose mapping.txt ~/trace.txt
However I'm unable to get raw form of stacktrace...
So I have 2 questions:
How can I get raw form from firebase crash reporting tab on their site?
How can I upload mapping file before publishing app into play store?
Currently, there's no way to get raw stack traces from Firebase Crash Reporting. So you need to copy them manually when viewing the detail of each error.
The problem is the deobfuscation doesn't work with that stack trace string copied from Firebase Crash Reporting, It's because of the missing at statement at the beginning of each line of the stack trace.
For example, this is what you get from Firebase Crash Reporting
Exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.models.User.getUserName()' on a null object reference
com.example.views.adapters.ExampleAdapter.a (SourceFile:110)
com.example.views.adapters.ExampleAdapter.a (SourceFile:31)
b.a.a.a.b.a (SourceFile:54)
b.a.a.a.b.a (SourceFile:54)
android.support.v7.widget.RecyclerView$a.a (SourceFile:6279)
android.support.v7.widget.RecyclerView$a.b (SourceFile:6312)
You just need to add at at the beginning of each line that contains SourceFile string. The result should look like this
Exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.models.User.getUserName()' on a null object reference
at com.example.views.adapters.ExampleAdapter.a (SourceFile:110)
at com.example.views.adapters.ExampleAdapter.a (SourceFile:31)
at b.a.a.a.b.a (SourceFile:54)
at b.a.a.a.b.a (SourceFile:54)
at android.support.v7.widget.RecyclerView$a.a (SourceFile:6279)
at android.support.v7.widget.RecyclerView$a.b (SourceFile:6312)
With this new string, you should be able to deobfuscate the stack trace as usual.
I know, that's a lot of work especially when there are multiple errors occurred but this is the current workaround until the Firebase Crash Reporting team decided to enable a feature to download raw stack traces or just put the at string at the details instead of trimming that out.
Firebase team just recently released a Crash Reporting plugin for this purpose. The guide is here - Uploading ProGuard mapping files with Gradle
Honestly, I haven't been able to enable this plugin successfully, still confused by the guide. I really hope they will make it as simple as in Fabric Crashlytics, by just adding ext.enableCrashlytics = true in the build.gradle file.
There's also another way, by purposely crashing the app before release, then generate a new release APK without the error, and then you can upload the mapping.txt file to Firebase Crash Reporting console. :)

Categories

Resources