프로그래밍/Android

[안드로이드] Firebase Crashlytics 연동방법

Lou Park 2021. 1. 15. 10:30

구글 Firebase Document에 나와있지만 한국어로 설정하면 보이지 않는 문제가 있어서 블로그에 포스팅한다. Firebase Crashlytics 통합을 위한 절차는 다음과 같다.

미리 해야 할 일

Firebase에서 프로젝트를 생성하고, google-services.json 파일을 안드로이드 프로젝트에 넣는 작업이 완료된 후 Firebase를 사용 할 준비가 되어있어야 한다. 여기까지의 단계는 (https://firebase.google.com/docs/android/setup[https://firebase.google.com/docs/android/setup]) 에서 따라 할 수 있다.

 

app/build.gradle

plugins {
    ...
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}

dependencies {
    // - BoM 사용시 출시시점에 FB 라이브러리가 사용가능한 최신버전으로 됨
    implementation platform('com.google.firebase:firebase-bom:26.1.1')
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'
}

 

project/build.gradle

buildscript {

  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }

  dependencies {
    // ...

    // Add the following line:
    classpath 'com.google.gms:google-services:4.3.4'  // Google Services plugin
  }
}

allprojects {
  // ...

  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    // ...
  }
}

 

프로젝트의 Application 클래스

class BaseApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Crashlytics가 Debug 모드에서는 작동하지 않도록 함
        FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
    }
}

 

AndroidManifest.xml

방금 만든 BaseApplication 클래스를 연결시켜주면 완성!

<application
        android:name=".base.BaseApplication"
        android:icon="@mipmap/ic_launcher" 
        ...>
</application>