我創建了一個新項目并通過firebase的android studio工具添加了firebase。按照指示做了所有事情,但我在午餐應用程序期間收到此錯誤。Process: com.chitchat, PID: 20084java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chitchat/com.chitchat.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.chitchat. Make sure to call FirebaseApp.initializeApp(Context) first. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6718) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.chitchat. Make sure to call FirebaseApp.initializeApp(Context) first.
3 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
在您的類中添加以下代碼Application而不是Activity,以便將 Firebase 初始化到整個應用程序中,而不僅僅是一個 Activity
@Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
此外,您需要將應用插件代碼從上到下移動 參考:添加Firebase SDK
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
它要求該apply plugin: 'com.google.gms.google-services'行位于文件的底部,app/build.gradle以免引入依賴沖突。您可以通過運行 ./gradlew 查看此步驟的結果:app:dependencies。參考
此外,嘗試將所有 firebase 和 gms:google-services 依賴項同步到最新版本。
添加回答
舉報
0/150
提交
取消