Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

FacebookSdk.sdkInitialize. The sdk has not been initialized #485

Open
gazedash opened this issue Feb 25, 2019 · 17 comments
Open

FacebookSdk.sdkInitialize. The sdk has not been initialized #485

gazedash opened this issue Feb 25, 2019 · 17 comments

Comments

@gazedash
Copy link

gazedash commented Feb 25, 2019

Environment

Run react-native info in your terminal and paste its contents here.

Description

Run Sample react-native project and this error appears
Describe your issue in detail. Include screenshots if needed. If this is a regression, let us know.

Reproducible Demo

Let us know how to reproduce the issue. Include a code sample, share a project, or share an app that reproduces the issue using https://snack.expo.io/.
Please follow the guidelines for providing a MCVE: https://stackoverflow.com/help/mcve

@M1K3Yio
Copy link

M1K3Yio commented Feb 25, 2019

I had this same error when I was first configuring this, I don't know what it was, but if you follow https://developers.facebook.com/docs/facebook-login/android there's some things that are different, then what is listed here in the setup process.

@gazedash
Copy link
Author

@M1K3Yio thanks a lot, could you maybe point out what is required to make it work?

@Asim13se
Copy link

Asim13se commented Mar 1, 2019

@gazedash add FacebookSdk.sdkInitialize(getApplicationContext()); to onCreate() in MainApplication.java
like this:

@Override
  public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
  }

I think this should be in the README along with the other instructions

@SamiChab
Copy link

This helped me: https://stackoverflow.com/a/47463456/8577483

@cogell
Copy link

cogell commented May 9, 2019

@Asim13se Hm, Android Studio complains about sdkInitialize being deprecated.

@ondrej-merkun
Copy link

Here's a solution that worked for me - https://stackoverflow.com/a/51651988/7902116

@betranthanh
Copy link

betranthanh commented Jul 3, 2019

Open AndroidManifest.xml insert into <application> tag

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

Open strings.xml add
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>

@pavinduLakshan
Copy link

@SamiChab Your solution did work for me..

Quoting from Stack Overflow:

  1. Open android/app/src/main/AndroidManifest.xml file and look in the <application> tag to confirm that this meta-data tag exists:
         <meta-data android:name="com.facebook.sdk.ApplicationId"
          android:value="@string/facebook_app_id"/>
  1. Open android/app/src/main/res/values/strings.xml file and confirm that this there is a "facebook_app_id" string tag with your app id as the value:
    <string name="facebook_app_id">YOUR_APP_ID_HERE</string>

  2. Run react-native run-android.

@zyonnetworks
Copy link

I've following the AndroidManifest.xml and strings.xml and getting the same error

The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

react-native-fbsdk 1.0.4
react-native 61.2

@cobyhausrath
Copy link

Despite sdkInitialize being labeled deprecated, the solution from @Asim13se was exactly what I needed to get the Android app to not crash immediately in release mode with this error. (App ID was set properly.)

react-native-fbsdk@1.0.4
react-native@0.61.2

@ZeeshanAhmadKhalil
Copy link

ZeeshanAhmadKhalil commented Nov 15, 2019

Open AndroidManifest.xml insert into tag

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

Open strings.xml add
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>

@betranthanh how I could get my applicationId ?. I used the one from gradle.build and also the one from AndroidManifest but whenever i add meta-data tag in application tag i get unsuccessful build.

@ZeeshanAhmadKhalil
Copy link

Damit! I was not enclosing applicationId in double-quotes, which was causing the error for me

@henoktsegaye
Copy link

henoktsegaye commented Jan 3, 2020

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

make sure you paste this as it is in your manifest file
and after that
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>

This error happens when the string couldn't be found in the string under the name facebook_app_id.

@DevAelius
Copy link

DevAelius commented Mar 2, 2020

putting below code in string.xml file will fix the issue

<string name="facebook_app_id">your-fb-app-id</string>
<string name="fb_login_protocol_scheme">fbyour-fb-app-id-</string>

suppose your fb-app-id is 012345678912345
e.g.

<string name="facebook_app_id">012345678912345</string>
<string name="fb_login_protocol_scheme">fb012345678912345-</string>

from docs https://developers.facebook.com/docs/facebook-login/android

Look for point no 4 Edit Your Resources and Manifest

after putting code in string.xml file we have to init in AndroidManifest.xml file as

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

under the application tag

<application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      **<meta-data 
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />**
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

then rebuild the whole app & run

hope this will be fixed your issue

@mr-shitou
Copy link

mr-shitou commented Apr 24, 2020

I dont know is this rigtt to issue here,
Anyway,
when I use https://developers.facebook.com/docs/app-events/getting-started-app-events-android, i get this problem
And this is crazy,old project is good with same setting same version 5.13.0,the new project get this problem
"The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first"
But as doc says it should already be done when application start,it's confused
I finally set this code to my application's onCreate() function with I tried several methods which can not dont know is this rigtt to issue here,
Anyway,
when I use https://developers.facebook.com/docs/app-events/getting-started-app-events-android, i get this problem
And this is crazy,old project is good with same setting same version 5.13.0,the new project get this problem
"The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first"
But as doc says it should already be done when application start,it's confused
I finally set this code to my application's onCreate() function with I tried several methods which can not solve this problem
it finally work good!!!
But the import is I can not figure out,i think it should be explain in the doc
Plus,I don't know it’s my fault or sdk problem,if it‘s my fault sorry for this issue

@tibbus
Copy link

tibbus commented Apr 29, 2020

Wow, I'm just amazed how idiot I am, I've lost hours on this... In case someone did it like me:

I've had it like this:

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

Which is totally wrong, it should be literally:
android:value="@string/facebook_app_id" as it reads from the strings.xml file

@josebarrontovar
Copy link

josebarrontovar commented May 25, 2020

Open AndroidManifest.xml insert into <application> tag

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

Open strings.xml add
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests