Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()

Hey I know this was asked before, but none of the solutions seem to help. I'm using first time Facebook SDK in my application.

What I've tried:

I had tried most of the things found on Internet but did not get anything regarding this.

Here is my MainActivity.java:

 public class MainActivity extends Activity {    @Override   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);     FacebookSdk.sdkInitialize(getApplicationContext());    }  } 

Here is My Activitymain.xml:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:facebook="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">   <com.facebook.login.widget.LoginButton     android:id="@+id/connectWithFbButton"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerInParent="true"     android:layout_gravity="center_horizontal"     android:text="  connect_with_facebook" />  </LinearLayout> 

see my Logcat:

 05-13 16:30:39.332: E/AndroidRuntime(10264): Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first. 
like image 877
Tufan Avatar asked May 13 '15 11:05

Tufan


People also ask

How do I set up Facebook SDK?

Configure Your Facebook App for Android First, log into Facebook developer account and do the following: Go to the App Dashboard; Click My Apps and create a new app; Go to Settings > Basic to see the App Details Panel with your App ID, App Secret as well as other app details.


2 Answers

You have to use FacebookSdk.sdkInitialize(getApplicationContext()); before setContentView(R.layout.activity_main); as documentation states out. In case you need a complete facebook login example, check this one here.

like image 66
Menelaos Kotsollaris Avatar answered Sep 23 '22 05:09

Menelaos Kotsollaris


Problem

While integrating Android SDK for a react-native project, I had finished the Android with React Native v0.30+ Project Configuration guide, and ran react-native run-android and then got this screen:

I learned that FacebookSdk.sdkInitialize is deprecated. see here

After some searching, I realized that the guide did not contain the steps to add the Facebook App ID for my app.

Solution

  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"/> 
  2. 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> 
  3. Run react-native run-android.

These are the steps that worked for me.

like image 22
Beau Smith Avatar answered Sep 25 '22 05:09

Beau Smith