Firebase Crash reporting has been deprecated since plugin version 5.3.0 and was removed in plugin version 9.0.0 - use Crashlytics instead.
You will be prompted during installation of the plugin to enable Crashlytics (off by default).
This will add "crashlytics": true
to your firebase.nativescript.json
file, now remove the platforms
folder so this change is picked up.
Since plugin version 8.3.0 you can disable Crashlytics collection by default, and enabled it at runtime.
Add this to your AndroidManifest.xml
and this to your Info.plist
, so it's disabled by default.
You can then either pass crashlyticsCollectionEnabled: true
in firebase.init()
,
or call crashlytics.setCrashlyticsCollectionEnabled(true)
to enabled Crashlytics collection for the user.
When setting up Crashlytics, select "This app is new to Crashlytics" and press "Next". Then the screen changes to something like "waiting for your first crash report". Then produce a crash, and it can easily take a day before that screen changes (later data comes in much quicker).
Send a native iOS or Android exception to Crashlytics.
// for NativeScript 7, import like this:
import { crashlytics } from "@nativescript/firebase/crashlytics";
// for older versions of NativeScript, either import like this:
import { crashlytics } from "nativescript-plugin-firebase"; // and do: crashlytics.sendCrashLog
// or this:
import { crashlytics as firebaseCrashlytics } from "nativescript-plugin-firebase"; // and do: firebaseCrashlytics.sendCrashLog
// or this:
import * as firebase from "nativescript-plugin-firebase"; // and do: firebase.crashlytics.sendCrashLog
import { isAndroid, isIOS } from "tns-core-modules/platform";
if (isAndroid) {
crashlytics.sendCrashLog(new java.lang.Exception("test Exception"));
} else if (isIOS) {
crashlytics.sendCrashLog(new NSError({
domain: 'ShiploopHttpResponseErrorDomain',
code: 42,
userInfo: null
}));
}
Set a value that will be logged with an error and showing in the Firebase console on the 'Keys' tab of the error details.
import { crashlytics } from "nativescript-plugin-firebase";
crashlytics.setString("test_key", "test_value");
crashlytics.setBool("test_key_bool", true);
crashlytics.setInt("test_key_int", 2);
crashlytics.setDouble("test_key_double", 56615.55548465);
crashlytics.setFloat("test_key", 54646.45);
crashlytics.setUserId("user#42");
Add a message that will be logged with an error and showing in the Firebase console on the 'Logs' tab of the error details.
crashlytics.log("more log info...");
For easier testing, version 8.2.0 exposed this crash()
function of the native Firebase Crashlytics SDKs:
import { crashlytics } from "nativescript-plugin-firebase";
crashlytics.crash();
This should crash your app unless you have
discardUncaughtJsExceptions
set totrue
inapp/package.json
.