在我的Android应用程序中,我使用firebase登录谷歌,但无法在主要之前设置登录活动。 这是堆栈跟踪:
02-12 23:57:02.524 8692-8692/bf_d.binary_femaledefense E/AndroidRuntime: FATAL EXCEPTION: main
Process: bf_d.binary_femaledefense, PID: 8692
java.lang.RuntimeException: Unable to start activity ComponentInfo{bf_d.binary_femaledefense/bf_d.binary_femaledefense.login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source:54)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:0)
at bf_d.binary_femaledefense.login.onCreate(login.java:53)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我已经在onCreate方法中调用了FirebaseAuth.initializeApp(this)。但仍然在FirebaseApp中显示初始化错误。
这是我使用过的图书馆:
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
这是我的AndroidManifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".login"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity
android:name=".ContactSetup"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".EditContacts"
android:parentActivityName=".EditContacts" />
<activity
android:name=".HowTo"
android:parentActivityName=".MainActivity" />
<activity
android:name=".AboutDevs"
android:parentActivityName=".MainActivity" />
<activity
android:name=".RecordHistory"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CustomText"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".ContextSetup"
android:parentActivityName=".MainActivity" />
</application>
任何建议将不胜感激:)
答案 0 :(得分:0)
扩展Application类并在该类的FirebaseApp.initializeApp(this)
方法中调用onCreate()
:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
}
并将android:name
属性添加到您的清单
<application
android:name=". MyApplication"
...
>