A valid Facebook app id must be set in the AndroidManifest.xml
Asked Answered
A

4

9

I am trying to setup fbsdk on Android using react native and the fbsdk wrapper https://github.com/facebook/react-native-fbsdk. I have it working on iOS but I am stuck on Android. I followed all the steps according the github readme.

MainApplication.java

@Override
  public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    SoLoader.init(this, /* native exopackage */ false);
  }

strings.xml

<resources>
    <string name="app_name">FacebookLogin</string>
    <string name="facebook_app_id">1343643482425305</string>
    <string name="fb_login_protocol_scheme">fb1343643482425305</string>
</resources>

AndroidManifest.xml

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

But I am getting this error from LogCat

11-22 06:57:13.236 7570-7570/? I/zygote: Not late-enabling -Xcheck:jni (already on)
11-22 06:57:13.244 7570-7570/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
11-22 06:57:13.361 7570-7570/com.facebooklogin I/FacebookInitProvider: Failed to auto initialize the Facebook SDK
                                                                       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.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:20)
                                                                           at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)
                                                                           at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)
                                                                           at android.app.ActivityThread.installProvider(ActivityThread.java:6285)
                                                                           at android.app.ActivityThread.installContentProviders(ActivityThread.java:5851)
                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5772)
                                                                           at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                                                                           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)
11-22 06:57:13.364 7570-7570/com.facebooklogin D/AndroidRuntime: Shutting down VM
11-22 06:57:13.365 7570-7570/com.facebooklogin E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: com.facebooklogin, PID: 7570
                                                                 java.lang.RuntimeException: Unable to create application com.facebooklogin.MainApplication: 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.handleBindApplication(ActivityThread.java:5794)
                                                                     at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                                                                     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: 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.facebooklogin.MainApplication.onCreate(MainApplication.java:53)
                                                                     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
                                                                     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
                                                                     at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
                                                                     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) 
Autocephalous answered 22/11, 2017 at 7:19 Comment(0)
T
2

Add below in build.gradle(Module:app) file:

repositories {
    mavenCentral()
}

and

compile 'com.facebook.android:facebook-android-sdk:4.10.0'

now add below in AndroidManifest.xml file :

 <activity android:name="com.facebook.FacebookActivity"
           android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
           android:theme="@android:style/Theme.Translucent.NoTitleBar"
           android:label="@string/app_name" />

add following in activity_main.xml file :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.demonuts.fblogin.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:layout_marginLeft="10dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/text"/>

<com.facebook.login.widget.LoginButton
    android:id="@+id/btnfb"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
Tocci answered 22/11, 2017 at 7:44 Comment(1)
i already the top 3 sections added from the following the steps. It wasn't working. The last part is not necessary since I am using react native right?Autocephalous
L
14

The meta-data in my case were located out of the application scope. Normally, it should be located in your manifest like this:

<application>
      ...
      <meta-data
                android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/facebook_app_id" />
    </application>
Lustral answered 2/12, 2018 at 0:9 Comment(1)
I made same mistake. Thank you.Dilatometer
T
2

Add below in build.gradle(Module:app) file:

repositories {
    mavenCentral()
}

and

compile 'com.facebook.android:facebook-android-sdk:4.10.0'

now add below in AndroidManifest.xml file :

 <activity android:name="com.facebook.FacebookActivity"
           android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
           android:theme="@android:style/Theme.Translucent.NoTitleBar"
           android:label="@string/app_name" />

add following in activity_main.xml file :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.demonuts.fblogin.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:layout_marginLeft="10dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/text"/>

<com.facebook.login.widget.LoginButton
    android:id="@+id/btnfb"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
Tocci answered 22/11, 2017 at 7:44 Comment(1)
i already the top 3 sections added from the following the steps. It wasn't working. The last part is not necessary since I am using react native right?Autocephalous
Z
1

try replacing:

<string name="facebook_app_id">1343643482425305</string>

with

<string name="facebook_application_id">1343643482425305</string>

Zymotic answered 8/5, 2020 at 23:27 Comment(0)
O
0

I have same issue when I create a new project in Facebook develop console, and then all configure is right but without install Facebook in test device.

Just install Facebook app!!!! then the error log is dispear.

Overby answered 31/3, 2022 at 5:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.