반응형
Default FirebaseApp is not initialized 오류 발생 시
안드로이드에서 Firebase를 사용할 때, 종종 발생하는 오류입니다.
오류 메세지 자체에서는 FirebaseApp.initializeApp(context)를 호출하라고 보내는데, 이렇게 해도 오류가 해결되지 않는 경우가 많습니다.
해당 상황은 Firebase의 초기 설정에서 놓친 부분이 있는 경우가 대다수입니다.
일단 제 프로젝트에서 초기 설정을 살펴보면서 문제를 해결해보도록 하겠습니다.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
우선 프로젝트 수준의 build.gradle 파일을 살펴보겠습니다.
Android Studio에서는 google-services의 최신 버전인 4.2.0 버전을 사용하라고 권고합니다.
해당 사항을 수정하겠습니다.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.kentastudio.izonestream"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
}
그 다음 어플리케이션 수준의 build.grade 파일입니다.
보통 문서를 찾아보면 gms.google-services 부분을 파일의 끝에 넣으라는 권고가 많아 해당 부분과
firebase-messaging 라이브러리의 버전을 바꾸도록 하겠습니다.
알림이 제대로 작동하는 것을 확인할 수 있습니다.
보통 Default FirebaseApp is not initialized 오류는 설정을 다시 한번 확인해보면 간단하게 해결할 수 있습니다.
반응형