15
votes

I followed all the steps on the docs to use Firebase Crash Reporting in my Android app (I use Android Studio and everything is up-to-date).

I used their own code to throw an exception to see if it works:

try {
    throw new NullPointerException();
} catch (NullPointerException ex) {
    FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
    FirebaseCrash.report(ex);
}

And the console gives me this log:

E/MainActivity: NPE caught

V/FirebaseCrash: Firebase Crash Reporting is disabled.

Here is one build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // Firebase - Google Services 3.0.0
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Here is the other build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-N'
    buildToolsVersion '24.0.0-rc2'

    defaultConfig {
        applicationId "com.app.test"
        minSdkVersion 19
        targetSdkVersion 'N'
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            useProguard true
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:24.0.0-alpha1'
    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
    compile 'com.android.support:design:24.0.0-alpha1'
    compile 'com.google.firebase:firebase-core:9.0.0'
    compile 'com.google.firebase:firebase-analytics:9.0.0'
    compile 'com.google.firebase:firebase-crash:9.0.0'
    compile 'com.google.firebase:firebase-messaging:9.0.0'
    compile 'com.google.firebase:firebase-config:9.0.0'
    compile 'com.google.firebase:firebase-invites:9.0.0'
    compile 'com.google.android.gms:play-services-appindexing:9.0.0'
}

apply plugin: 'com.google.gms.google-services'

I also use:

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
FirebaseMessaging.getInstance().subscribeToTopic("news");
Log.d(TAG, "Subscribed to news topic");

I added all dependencies that I'll need, but I'm adding one by one and testing one by one, and Notifications works, Analytics: no idea, it takes about 24 hours to update, so until it does, I don't know if is working...

So, the thing is how can I enable it?

NOTE: I have all of the dependencies added including the crash and core ones, also the plugin and the classpath

Thank you in advanced.

6
Did you add also the google-services.json file? - Gabriele Mariotti
Yes, I followed all the steps on the docs and also on the console as I added the app - Minion
Can you please edit the question to include your gradle files, and any other places that you have called to Firebase methods? - WoogieNoogie
The device or emulator must have Google Play services 9.0.x installed. If your device has Google Play services 8.9.25 then Firebase Crash Reporting and Firebase Analytics will not work. Once the device/emulator is updated to the latest version of Google Play services, it should work as expected. - Arthur Thompson
Please check this video tutorial. It has full detailed explanation. - Chintan Rathod

6 Answers

20
votes

Please note the following:

  • After adding the SDK you can try using:

    FirebaseCrash.report(new Exception("My first Android non-fatal error"));

  • Errors take up to 20 minutes to show up in the Crash Reporting console. Check back to see your report there.

  • (It may seem obvious but) make sure you have:INTERNET and ACCESS_NETWORK_STATE permission.

5
votes

Crash reporting was not working for me too after correctly setting it up in my App. To fix this I visited my developer console, API Manager, and enabled the "Mobile Crash and Performance Reporting API". To find out exactly where you need to do this follow the steps on this page.

If you follow the steps in the link above, the logcat that has the text "E/FirebaseCrashSenderServiceImpl: Error sending crash report" gives you a URL to where you must go in the console to enable crash reporting.

1
votes

The FirebaseCrash is deprecated. The FirebaseCrashlytics.getInstance() should be used instead:

FirebaseCrashlytics.getInstance().log(message)
FirebaseCrashlytics.getInstance().recordException(throwable)

Source: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#add-logs

0
votes

Add following code: In Project-level build.gradle (/build.gradle):

buildscript {
dependencies {

// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}

In App-level build.gradle (//build.gradle):

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'


//Add following in In App-level build.gradle
compile 'com.google.firebase:firebase-crash:9.0.0'

Now sync your project, Use following code in your activity to throw exception:

FirebaseCrash.report(new Exception("App Name : My first Android non-fatal error"));

check android crash reporting tutorial using firebase for complete guidance.

0
votes

I had the same issue. Turns out I was missing dependency in my project gradle file. Try adding this. It should help.

buildscript {
      repositories {
        jcenter()
        // ...
      }

      dependencies {
        // ...
        classpath 'com.google.firebase:firebase-plugins:1.0.5'
      }
    }
0
votes

You should allow some time to show up. Even though the documentation says the errors will show up within 5 minutes, it can take up to 15-20 minutes. Also, you have to change your old modules to AndroidX by migrating it if you use native development. Finally, make sure that all the tools and plugins are added in the appropriate Gradle files.