我创建了一个新项目并通过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
提交
取消