Firebase

How to use Firebase Crashlytics to log non-fatal errors in an Android app?

Discover the steps to seamlessly add Firebase Crashlytics to your Android app. Effortlessly log, watch, and address non-fatal errors. Boost app stability and enhance user experience for your users.

Developer profile skeleton
a developer thinking

Overview

When creating Android apps, keeping a close eye on errors is key to good quality and happy users. Firebase Crashlytics provides a solid tool for logging non-fatal errors, helping developers spot and study issues that don’t break the app but can still mess with the user experience. Adding Firebase Crashlytics to an Android project lets developers use its great reporting tools to find, understand, and resolve non-fatal problems quickly, boosting app stability and performance.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to use Firebase Crashlytics to log non-fatal errors in an Android app?

Step 1: Add Firebase to the Android Project

  1. Head over to the Firebase Console and either start a new project or pick one you already have.
  2. Click on "Add app" and choose the "Android" platform.
  3. Register your app by entering the package name, then follow the steps to download the google-services.json file.
  4. Drop that google-services.json file into the app directory of your Android project.

Step 2: Modify `build.gradle` Files

  1. Open up the project-level build.gradle file and add this classpath in the dependencies section:
    ```gradle
    classpath 'com.google.gms:google-services:4.3.10'
    ```

  2. Now, open the app-level build.gradle file and apply the Google Services plugin at the bottom:
    ```gradle
    apply plugin: 'com.google.gms.google-services'
    ```

  3. Add the Crashlytics dependency:

\`\`\`gradle
dependencies {
    implementation 'com.google.firebase:firebase-crashlytics:18.2.10'
}
\`\`\`
  1. Sync your project with the Gradle files.

Step 3: Initialize Firebase and Crashlytics

  1. Open your application class (or create one if it doesn't exist) and extend Application.

  2. Initialize Firebase and Crashlytics:
    ```java
    import android.app.Application;
    import com.google.firebase.FirebaseApp;
    import com.google.firebase.crashlytics.FirebaseCrashlytics;

    public class MyApplication extends Application {
    @Override
    public void onCreate() {
    super.onCreate();
    // Initialize Firebase
    FirebaseApp.initializeApp(this);
    // Optionally enable Crashlytics debug mode
    FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
    }
    }
    ```

  3. Register the application class in your AndroidManifest.xml file:
    ```xml
    <application
    android:name=".MyApplication"
    ... >
    ```

Step 4: Log Non-fatal Errors

  1. To log non-fatal errors or exceptions, use this code wherever an error needs to be logged:
    ```java
    try {
    // code that may throw an exception
    } catch (Exception e) {
    FirebaseCrashlytics.getInstance().recordException(e);
    }
    ```
    This will record caught exceptions as non-fatal errors in Crashlytics.

  2. For custom logs, use:
    ```java
    try {
    // custom log message
    FirebaseCrashlytics.getInstance().log("Your custom log message");
    } catch (Exception e) {
    FirebaseCrashlytics.getInstance().recordException(e);
    }
    ```

Step 5: Verify Crashlytics Setup

  1. Go to the Firebase Console, navigate to Crashlytics, and make sure the initial setup is complete.
  2. Use the test method provided by Firebase to check if Crashlytics is working:
    ```java
    FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
    FirebaseCrashlytics.getInstance().log("Testing Crashlytics setup");
    FirebaseCrashlytics.getInstance().recordException(new Exception("Test non-fatal error"));
    ```

Add this code in an activity and launch the app. Check for the reported non-fatal error in the Firebase Console under Crashlytics.

Explore more Firebase tutorials

Complete Guide to Firebase: Tutorials, Tips, and Best Practices

Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.