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

Kelvin picture Kelvin · Nov 22, 2017 · Viewed 8.8k times · Source

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) 

Answer

Andrii Artamonov picture Andrii Artamonov · Dec 2, 2018

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>