尝试连接Firebase和FB Auth并获取错误

时间:2018-01-20 06:01:45

标签: android facebook firebase firebase-authentication

尝试将FB Auth连接到Firebase。出现错误

FATAL EXCEPTION: main
              Process: com.borisruzanov.social, PID: 20684
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.borisruzanov.social/com.borisruzanov.social.FacebookLoginActivity}: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6119)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
               Caused by: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
                  at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:276)
                  at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:232)
                  at com.borisruzanov.social.FacebookLoginActivity.onCreate(FacebookLoginActivity.java:49)
                  at android.app.Activity.performCreate(Activity.java:6679)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.borisruzanov.social">

    <uses-permission android:name="android.permission.INTERNET"/>
    <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=".AuthPage">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".GoogleSignInActivity" >
        </activity>
        <activity android:name=".PhoneAuthActivity" >
        </activity>

        <activity android:name=".FacebookLoginActivity"
            >
            <meta-data android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/facebook_app_id"/>
        </activity>

        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>
    </application>

</manifest>

而且我也不明白为什么SDK的初始化不是实际的并且它被描述。我已经尝试过堆叠的解决方案。没有帮助。

此外,如果any1知道Firebase和Facebook auth集成良好的好例子吗?因为总是火柱引导完全崩溃了我的大脑。

2 个答案:

答案 0 :(得分:0)

您需要添加

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //initialize Facebook SDK
    FacebookSdk.sdkInitialize(getApplicationContext());
    if (BuildConfig.DEBUG) {
        FacebookSdk.setIsDebugEnabled(true);
        FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
    }

    setContentView(R.layout.activity_main); }

需要向应用程序添加元数据

<application android:label = "@string/app_name" ... > 
    ...
    <meta-data android:name = "com.facebook.sdk.ApplicationId" android:value = "@string/facebook_app_id" />  
    ...
</ application>

而不是

<activity android:name=".FacebookLoginActivity"
    >
    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>
</activity>

答案 1 :(得分:0)

您不需要在自动初始化时手动初始化FacebookSDK,只需更改您的清单文件,如@Boris所示。希望它现在可以运作。