Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase crashlytics doesnt show crashes

Wanted to get a crash report from firebase once the app gets crashed. Is it possible to get debug mode logs separate and production crash log separate in firebase crash?...because its not really clear when we get crash from production or debug test. Also, firebase won't reflect crash report on the console after a crash happens. What should I do to get up to date crash report? Is there another way to get a crash report other than firebase? I have updated the libraries which required for the firebase crashlytics. and Followed tutorial - https://firebase.google.com/docs/crashlytics/get-started#android

like image 964
Meera Potdar Avatar asked Jan 02 '19 06:01

Meera Potdar


People also ask

How do I find out crashes in Firebase Crashlytics?

Open your app from the home screen of your test device or simulator. In your app, press the "Test Crash" button that you added using the code above. After your app crashes, run it again from Xcode so that your app can send the crash report to Firebase.

What happened to Crashlytics?

In January 2017, Crashlytics and Fabric were acquired by Google. In September 2018, Google announces that Fabric will be deprecated and developers should use Crashlytics via Firebase.

Is Crashlytics real time?

Firebase Crashlytics, a real time crash reporting tool, helps you prioritize and fix your most pervasive crashes based on the impact on real users. Crashlytics also easily integrates into your Android, iOS, macOS, tvOS, and watchOS apps.

How does Firebase Crashlytics work?

Crashlytics helps you to collect analytics and details about crashes and errors that occur in your app. It does this through three aspects: Logs: Log events in your app to be sent with the crash report for context if your app crashes. Crash reports: Every crash is automatically turned into a crash report and sent.


3 Answers

Is it possible to get debug mode logs separate and production crash log separate in firebase crash?

It's common practice or perhaps even recommended that you create a separate project for testing and production. Download and place the google-services.json in your build flavor folder

  • ~/app/src/release/google-services.json
  • ~/app/src/debug/google-services.json

Even if you are only having a single Firebase project for test and production, you can filter your logs by the application id if you're setting up a project id suffix for the development build flavor:

~/app/build.gradle

buildTypes {
  release {
  }
  debug {
    applicationIdSuffix '.debug'
    versionNameSuffix '-dbg'
  }
}

Here you can see the different flavors being available in Crashlytics

enter image description here

Also, firebase won't reflect crash report on the console after a crash happens.

First time that you set up crashlytics it might take some time before the data shows up in the dashboard. But if it's been over 24 hours, it's likely that it's not properly set up. Try to explicitly trigger a crash to make sure that it works fine.

Button crashButton = new Button(this);
crashButton.setText("Crash!");
crashButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Crashlytics.getInstance().crash(); // Force a crash
    }
});

Is there another way to get a crash report other than firebase?

Yes you can have more than one crash reporting tool if you have the need. You can perhaps create a wrapper class for crash reporting where you abstract the call to Crashlytics and you can add or change the underlying reporting platform there.

like image 60
Dennis Alund Avatar answered Oct 18 '22 02:10

Dennis Alund


Upgrade SDK

After making the relevant settings for the migration to the new SDK, it is important to avoid the following error:

Attempting to send crash report at time of crash.

This can be caused by forcing a crash (without a button listen in my case) before FirebaseCrashlytics send the reports, that is, the Crashlytics Reports Endpoint upload is completed.


Test implementation

Enable Crashlytics debug logging

$ adb devices 
$ adb shell setprop log.tag.FirebaseCrashlytics DEBUG
$ adb logcat -s FirebaseCrashlytics

1) First step: DONT force a crash and run the app. Observing how in the Crashlyticis logcat it is initialized correctly.

...
FirebaseCrashlytics: Update app request ID: 1d62cb...
FirebaseCrashlytics: Result was 204.
Crashlytics Reports Endpoint upload complete

2) Step Two: Force a crash (with a button or directly).

MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    setupCrashlytics()

    ...
 }

 private fun setupCrashlytics() {
     throw RuntimeException("Test crash")  //TODO: Clean
 }

Note: The only thing necessary to generate a report is this code in addition to the dependencies. Additionally you can login custom keys with FirebaseCrashlytics.getInstance().

Then run the app and check the following:

FirebaseCrashlytics: Crashlytics completed exception processing. Invoking default exception handler.
FirebaseCrashlytics: Attempting to send crash report at time of crash...

At this point the exception process is logged on the Firebase server but the reports have not yet been sent to the console, that is, the upload is incomplete.

3) Finally, we clean or comment on the crash crash

private fun setupCrashlytics() {
     //throw RuntimeException("Test crash")
}

Run app and let's check:

Attempting to send 1 report(s)
FirebaseCrashlytics: Settings result was: 200
FirebaseCrashlytics: Adding single file 5EDA9D7....cls to report 5EDA9D7...
FirebaseCrashlytics: Sending report to: https://reports.crashlytics.com/spi/v1/platforms/android/apps/.../reports
FirebaseCrashlytics: Crashlytics Reports Endpoint upload complete: 5EDABB42 ...

This guarantees that the report reached the console.

GL

like image 6
Braian Coronel Avatar answered Oct 18 '22 01:10

Braian Coronel


Firebase will not differentiate between debug and production versions logs/crashes in crashlytics if you have set auto collection of logs. You can use a logging library to only send logs and crashes if the app build.gradle has debug:fasle i.e. production. You can look at the Timber logging library which has a great example of adding crash reporting. https://github.com/JakeWharton/timber

You have to disable the auto initialization of crashlytics in manifest to have control when crashes are sent to firebase

<meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="false" />

Then in your Application class's onCreate you check if BuildConfig.DEBUG is true you will not initialize crashlaytics so your debug logs and exceptions will not go to firebase, resulting in only production crashes.

For timber when you want to put logs and crashes to firebase you can use this Tree:

/**
     * {@link Timber.Tree} using {@link Crashlytics} as crash reporting
     */
    private static class CrashReportingTree extends Timber.Tree {

        CrashReportingTree(Context context) {
            CrashlyticsCore core = new CrashlyticsCore.Builder()
                    .disabled(BuildConfig.DEBUG)
                    .build();
            Fabric.with(context, new Crashlytics.Builder().core(core).build());
        }

        @Override
        protected void log(int priority, String tag, @NonNull String message, Throwable t) {
            // don't report log to Crashlytics if priority is Verbose or Debug
            if (priority == Log.VERBOSE || priority == Log.DEBUG) {
                return;
            }
            Crashlytics.log(priority, tag, message);

            if (t != null) {
                if (priority == Log.ERROR) {
                    Crashlytics.logException(t);
                }
            }

        }
    }

For debug mode you should not send crashes to firebase as you can check the debug logs locally.

like image 2
Umar Hussain Avatar answered Oct 18 '22 00:10

Umar Hussain