기본 FirebaseApp이 초기화되지 않았습니다
Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
Firebase Remote Config를 추가 한 Android 앱 메시지 에 몇 가지 예외가 있습니다.
스택 추적은 다음과 같습니다.
Fatal Exception: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance(Unknown Source)
at com.example.app.fragments.SomeFragment.updateFooter(SourceFile:295)
at com.example.app.fragments.SomeFragment.onCreateView(SourceFile:205)
at android.support.v4.app.Fragment.performCreateView(SourceFile:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1290)
at android.support.v4.app.BackStackRecord.run(SourceFile:801)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(SourceFile:1638)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(SourceFile:679)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(SourceFile:143)
at android.support.v4.view.ViewPager.populate(SourceFile:1240)
at android.support.v4.view.ViewPager.populate(SourceFile:1088)
at android.support.v4.view.ViewPager.setAdapter(SourceFile:542)
at com.example.app.SomeActivity.onSomeAsyncCallback(SourceFile:908)
at com.example.app.SomeDataRetriever.onAsyncHttpCompleted(SourceFile:72)
at com.example.app.io.AsyncHttp.onPostExecute(SourceFile:141)
at com.example.app.io.AsyncHttp.onPostExecute(SourceFile:19)
at android.os.AsyncTask.finish(AsyncTask.java:679)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:696)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
이 버전은 9.6.1이며 다른 Firebase 구성 요소도 사용하고 있습니다.
compile 'com.google.firebase:firebase-ads:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-invites:9.6.1'
compile "com.google.firebase:firebase-messaging:9.6.1"
문서 와 Javadoc 에서 볼 수 있듯이 우리의 경우 수동 초기화를 수행 할 필요가 없습니다.
다양한 기기의 Android 4-6에서는 예외가 발생합니다.
편집하다:
이 질문에 약간의주의가 필요합니다. 나는이 설명이 당신 중 일부에게 흥미로울 수 있다고 생각합니다 : https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html
얼마 전에 같은 문제가있었습니다.
초기화하지 않고 Firebase 인스턴스를 얻으려고합니다. Firebase 인스턴스를 가져 오기 전에 다음 코드 줄을 추가하십시오.
FirebaseApp.initializeApp(this);
루트 레벨 build.gradle에 추가하십시오
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
그런 다음 모듈 레벨 Gradle 파일 (일반적으로 app / build.gradle)에서 파일 하단에 'apply plugin'행을 추가하여 Gradle 플러그인을 활성화하십시오.
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:9.6.1'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
문서 에서 말했듯이 . 내 gradle 파일에 이것을 추가하는 것을 잊었을 때 위의 질문에서 예외가있었습니다.
google-services:4.1.0
문제가있는 것 같습니다 . 다운 그레이드
classpath 'com.google.gms:google-services:4.0.0'
또는 그것을 업그레이드
classpath 'com.google.gms:google-services:4.2.0'
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
classpath 'com.google.gms:google-services:4.2.0'
/*classpath 'com.google.gms:google-services:4.1.0' <-- this was the problem */
}
그것이 도움이되기를 바랍니다.
app / build.gradle 파일 에서 아래 줄이 누락되었습니다.
apply plugin: 'com.google.gms.google-services'
일단 프로젝트를 정리 하고 다시 실행하십시오. 그것은 나를 위해 그것을 고쳤다.
classpath 'com.google.gms:google-services:4.1.0'
문제가 있습니다. 대신 다음을 사용하십시오.
classpath 'com.google.gms:google-services:4.2.0'
루트 수준 build.gradle에서 com.google.gms : google-services : xxx를 먼저 추가해야합니다.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
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
}
}
그런 다음 app / build.gradle에서 'com.google.gms.google-services'플러그인을 적용해야합니다.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.google.android.gms:play-services-gcm:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
여전히 문제가 발생하면 추가해야합니다.
FirebaseApp.initializeApp(this);
전화하기 직전에
FirebaseInstanceId.getInstance().getToken();
다양한 종속성을 업데이트 한 후 컴파일에서 Crashlytics 오류가 발생했습니다. 'Crashlytics에서 잘못된 API 키를 찾았습니다 : null. Crashlytics 플러그인을 확인하여 응용 프로그램이 성공적으로 추가되었는지 확인하십시오! 도움이 필요하면 support@fabric.io에 문의하십시오. ' support@fabric.io에 대한 반복적 인 시도에서 얻은 비 자동 응답 중 하나는 Fabric과 Crashlytics가 별도의 팀이므로 나를 도울 수 없다는 오류입니다. Crashlytics에 추가 Fabric 계층을 구현하지 않고 Fabric 사이트에서 새 키를 얻거나 사이트를 인식하지 못했습니다. 내 코드에서 Crashlytics를 제거 하여이 문제를 해결하려고 할 때 '기본 FirebaseApp 이이 프로세스 com.example.app에서 초기화되지 않았습니다. 실행 중에 FirebaseApp.initializeApp (Context) '충돌을 먼저 호출해야합니다.
'FirebaseApp.initializeApp (this)'의 초기화 줄을 추가 할 필요가 없었으며 실제로 주석 처리되었습니다. 한 활동에 Firebase 만 사용하는 경우 문서에는 이것을 필요로하지 않습니다. 추가해도 아무런 차이가 없었지만 여전히 실행 종료 오류가 발생했습니다.
새로운 모호한 오류의 원인은 업데이트 된 google-services 종속성이었습니다. 지금은 새로운 종속성으로 인한 샷건 오류를 해결하기 위해 더 많은 시간을 할애 할 시간이 없으므로 누군가가 솔루션을 만들 때까지 이전 버전을 고수 할 것입니다. 홀수 초기화 충돌 외에도 새 버전은 Fabric on Crashlytics 사용자를 강제 할 수 있습니다. 사용자는 이것에 대해서도 이전 종속성 버전으로 돌아가고 있습니다. Crashlytics가 잘못된 API 키를 찾았습니다 : null. com.google.gms : google-services : 4.1.0 업데이트 후
com.google.gms:google-services:4.1.0//BAD
com.google.gms:google-services:4.0.1//GOOD
10/17/18 편집 : 다음 종속성을 다시 업데이트 한 후
implementation 'com.google.firebase:firebase-ads:17.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.4
Google 서비스 종속성 업데이트를 시도했을 때와 같이 'xxx가 예기치 않게 닫혔습니다'라는 설치 시도에서 즉시 충돌이 발생했습니다. 로그를 파고 나는 이것을 매니페스트에 추가하라는 링크를 찾았습니다.
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxx~xxxxxx"/>
이 새로운이며, 여기에 설치 및 간질 지침에 언급되지 https://firebase.google.com/docs/android/setup 여기 https://developers.google.com/admob/android/interstitial을 .
예전에는 앱의 광고 관련 ID 인 INTERSTITIAL_UNIT_ID 만 처리해야했습니다. 이제 두 가지를 처리해야합니다. 위의 추가 외에도 문서는 여기에 ADMOB_APP_ID를 추가하도록 지시합니다 (새로운 매니페스트 코드에서 광고와 같은 번호).
MobileAds.initialize(this, ADMOB_APP_ID);
INTERSTITIAL_UNIT_ID 및 ADMOB_APP_ID ID는 Google AdMob 콘솔에서 확인할 수 있습니다. 내 게임 앱이 Firebase 종속성의 첫 번째 업데이트에서 광고 게재를 중단했지만 여전히 광고를 게재하지 않아
public void onAdFailedToLoad(int errorCode){...
이 추가 된 혼란이 있더라도 초기화 오류 실행 충돌없이 여전히 google-services 종속성을 업데이트 할 수 없습니다. 한동안 google-services : 4.0.1에 갇힐 것으로 예상됩니다.
18/24/18 수정 : 업데이트 후 광고가 게재되지 않도록 몇 주 동안 통신 후 mobileadssdk-advisor+support@google.com에서 :
'기기 로그를 공유해 주셔서 감사합니다. 로그에서 기존 문제처럼 보이며 이는 우선 순위 목록에 있으며 우리 팀은 수정 작업을 진행 중이며 이는 Android O 및 P 기기에서만 발생합니다. '
O 및 P 장치 만? O가 2017 년 9 월 25 일에 나온 마지막 두 버전입니다.
의견에서 @PSIXO가 언급했듯이 이는 google-services의 종속 버전에 문제가 될 수 있습니다. 나를 바꾸려고
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.1.0'
}
}
에
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1'
}
}
4.1.0 버전에 문제가있을 수 있습니다. 나는 이것에 많은 시간을 낭비했기 때문에 이것을 대답으로 생각했습니다.
당신이 사용하는 경우 FirebaseUI을 , 필요 의 FirebaseApp.initializeApp(this);
코드에서는 따라하지 샘플을 .
루트 레벨 build.gradle 에 추가하십시오 :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
...
classpath 'com.google.gms:google-services:3.1.1'
...
}
}
그런 다음 모듈 레벨 Gradle 파일에서 :
dependencies {
...
// 1 - Required to init Firebase automatically (THE MAGIC LINE)
implementation "com.google.firebase:firebase-core:11.6.2"
// 2 - FirebaseUI for Firebase Auth (Or whatever you need...)
implementation 'com.firebaseui:firebase-ui-auth:3.1.2'
...
}
apply plugin: 'com.google.gms.google-services'
그게 다야. 더 필요 없습니다.
build.gradle (프로젝트 수준) 에서 Firebase Gradle 빌드 스크립트 종속성을 추가해야합니다.
classpath 'com.google.gms:google-services:3.1.0'
app / build.gradle 에 Gradle 용 Firebase 플러그인 추가
apply plugin: 'com.google.gms.google-services'
build.gradle will include these new dependencies:
compile 'com.google.firebase:firebase-database:11.0.4'
출처 : Android Studio Assistant
또 다른 가능한 해결책-베타 버전을 사용하는 경우 다른 Android Studio를 사용해보십시오. 나를 도와주었습니다. 새로운 Android Studio는 Firebase를 올바르게 추가하지 않았습니다. 내 경우에는 3.3 미리보기
좀 더 조사한 결과, 새로운 Android 스튜디오가 새로운 Google 서비스 버전으로 프로젝트를 시작하고 원래 문제인 것으로 나타났습니다. @ Ammar Bukhari가 제안한 것처럼이 변경이 도움이되었습니다.
클래스 경로 'com.google.gms : google-services : 4.1.0'-> 클래스 경로 'com.google.gms : google-services : 4.0.0'
Google 서비스 버전과 firebase 버전에 호환성 문제가 있다고 생각합니다.
프로젝트의 build.gradle 파일에서 종속성을 변경했습니다.
클래스 경로 'com.google.gms : google-services : 4.1.0'~ 4.2.0
그런 다음 모듈의 build.gradle 종속성을 다음과 같이 업데이트했습니다.
구현 'com.google.firebase : firebase-database : 16.0.6'
구현 'com.google.firebase : firebase-core : 16.0.7'
모든 것이 매력처럼 작동하므로 FirebaseApp.initializeApp (this)를 입력 할 필요가 없습니다.
필자의 경우 Google 서비스 gradle 플러그인이 values.xml
파일에서 필요한 파일을 생성하지 못했습니다 google-services.json
. Firebase 라이브러리는이 생성 된 값 파일을 사용하여 자체 초기화하며 값 파일을 찾을 수없는 경우 오류가 발생하지 않는 것으로 보입니다. 값 파일이 다음 위치에 있고 google-sevices.json
파일 의 해당 문자열로 채워져 있는지 확인 하십시오.
app/build/generated/res/google-services/{build_type}/values/values.xml
그리고 / 또는
app/build/generated/res/google-services/{flavor}/{build_type}/xml/global_tracker.xml
자세한 내용은 https://developers.google.com/android/guides/google-services-plugin을 참조하십시오.
내 특별한 경우는 내가 실행중인 Android Studio 버전에 비해 너무 고급 gradle 도구 버전을 사용했기 때문에 발생했습니다 (즉, Android Studio v3.2에서 등급 도구 v3.2.X-YYY를 실행하십시오).
com.google.gms : google-services (4.2.0 이하) 종속성에 문제가있는 Android Studio를 3.3.1로 최근 업데이트 한 경우 com.google.gms : google-services를 4.2.0으로 업데이트하십시오.
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
수동으로 전화를 걸 필요FirebaseApp.initializeApp(this);
는 없습니다 . 우리도 그렇게해서는 안됩니다.
방금 동일한 문제에 직면하여 예기치 않은 이상한 해결책을 얻었습니다.
에서 이 대답 :
나는 제거 tools:node="replace"
하고 매력처럼 작동합니다.
이 문제가 발생하는 이유는 com.google.gms : google-services version 입니다. 4.1.0 을 사용할 때 동일한 오류가 발생했습니다. 그런 다음 버전을 다운 그레이드합니다. 전에
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.1.0'
후
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:3.2.0'
희망은 오류를 해결할 것입니다.
나에게 build.gradle 내부의 com.google.gms : google-services의 종속성을
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
이 문제가 발생하는 이유 중 하나는 android.permission.INTERNET
권한을 추가하는 것을 잊어 버릴 수 있습니다 .AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
수동으로 Firebase를 초기화 FirebaseApp.initializeApp(this);
하여 오류가 사라지 더라도 근본 원인을 수정하지는 않지만 몇 가지 이상한 문제가 함께 해결되지 않는 것처럼 보입니다.
- FCM에는
com.google.android.c2dm.permission.RECEIVE
GCM 전용 권한이 필요합니다 - 첫 번째 알림 전송 후 토큰이 등록 취소됩니다
- 메시지가 수신되지 않음 / onMessageReceived ()는 호출되지 않습니다.
Use newer Gradle plugin (e.g. Android plugin 2.2.3 and Gradle 2.14.1) fixed everything. (Of course setup has to be correct as per Firebase documentation )
We will have to initialize Firebase in onCreate function of Application Class.
package com.rocks.music.videoplayer;
import android.app.Application;
import android.content.Context;
import com.google.firebase.FirebaseApp;
/**
* Created by ashish123 on 22/8/15.
*/
public class MyApplication extends Application {
private static MyApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
try {
FirebaseApp.initializeApp(this);
}
catch (Exception e) {
}
}
public static Context getInstance() {
return mInstance;
}
}
Code in manifest file:-
<application
android:name="com.rocks.music.videoplayer.MyApplication"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
My problem was not resolved with this procedure
FirebaseApp.initializeApp(this);
So I tried something else and now my firebase has been successfully initialized. Try adding following in app module.gradle
BuildScript{
dependencies {..
classpath : "com.google.firebase:firebase-plugins:1.1.5"
..}
}
dependencies {...
implementation : "com.google.firebase:firebase-perf:16.1.0"
implementation : "com.google.firebase:firebase-core:16.0.3"
..}
Click Tools > Firebase to open the Assistant window.
Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.
https://firebase.google.com/docs/android/setup
Installed Firebase Via Android Studio Tools...Firebase...
I did the installation via the built-in tools from Android Studio (following the latest docs from Firebase). This installed the basic dependencies but when I attempted to connect to the database it always gave me the error that I needed to call initialize first, even though I was:
Default FirebaseApp is not initialized in this process . Make sure to call FirebaseApp.initializeApp(Context) first.
I was getting this error no matter what I did.
Finally, after seeing a comment in one of the other answers I changed the following in my gradle from version 4.1.0 to :
classpath 'com.google.gms:google-services:4.0.1'
When I did that I finally saw an error that helped me:
File google-services.json is missing. The Google Services Plugin cannot function without it. Searched Location: C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\src\nullnull\debug\google-services.json
C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\src\debug\nullnull\google-services.json
C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\src\nullnull\google-services.json
C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\src\debug\google-services.json
C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\src\nullnullDebug\google-services.json
C:\Users\%username%\AndroidStudioProjects\TxtFwd\app\google-services.json
That's the problem. It seems that the 4.1.0 version doesn't give that build error for some reason -- doesn't mention that you have a missing google-services.json file. I don't have the google-services.json file in my app so I went out and added it.
But since this was an upgrade which used an existing realtime firsbase database I had never had to generate that file in the past. I went to firebase and generated it and added it and it fixed the problem.
Changed Back to 4.1.0
Once I discovered all of this then I changed the classpath variable back (to 4.1.0) and rebuilt and it crashed again with the error that it hasn't been initalized.
Root Issues
- Building with 4.1.0 doesn't provide you with a valid error upon precompile so you may not know what is going on.
- Running against 4.1.0 causes the initialization error.
use com.google.gms:google-services:4.0.1' instead of 4.1.0
changing
classpath 'com.google.gms:google-services:4.1.0'
to
classpath 'com.google.gms:google-services:4.0.1'
Works for me
Reason and solution: This is the common error you will get most of the time. Reason: when you integrate your project with the Firebase it adds the dependencies
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
and classpath
classpath 'com.google.gms:google-services:4.1.0'
you just need to update them
This is how you can update
go to gradle sript and do this
참고URL : https://stackoverflow.com/questions/40081539/default-firebaseapp-is-not-initialized
'Programing' 카테고리의 다른 글
프로세스가 종료되면 프로세스를 다시 시작하기 위해 bash 스크립트를 작성하는 방법 (0) | 2020.04.29 |
---|---|
재귀 또는 반복? (0) | 2020.04.29 |
정기적으로 어떤 Xcode 키보드 단축키를 사용하십니까? (0) | 2020.04.29 |
DROP 데이터베이스 권한없이 명령 행에서 모든 MySQL 테이블을 제거하는 방법은 무엇입니까? (0) | 2020.04.29 |
PostgreSQL에서 인덱스가있는 열 나열 (0) | 2020.04.29 |