6

I get the following error when trying to login by Facebook when using the latest SDK version which is 4.30:

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

Then the application crashes.

Although, in the official documentation it's supposed to be already auto initialized.

Note that FacebookSdk.sdkInitialize() is deprecated now so it should not be called!

Error Log when not calling FacebookSdk.sdkInitialize() :

  The SDK has not been initialized, make sure to call
 FacebookSdk.sdkInitialize() first.   at
 com.facebook.internal.Validate.sdkInitialized(Validate.java:143)   at
 com.facebook.login.LoginManager.<init>(LoginManager.java:79)    at
 com.facebook.login.LoginManager.getInstance(LoginManager.java:92)   
 at
 com.linkdev.tepdeal.login.LoginPresenter.loginWithFacebook(LoginPresenter.java:88)
 at
 com.linkdev.tepdeal.login.FragmentLogin.onClick(FragmentLogin.java:105)
 at android.view.View.performClick(View.java:5637) at
 android.view.View$PerformClick.run(View.java:22433)    at
 android.os.Handler.handleCallback(Handler.java:751)     at
 android.os.Handler.dispatchMessage(Handler.java:95) at
 android.os.Looper.loop(Looper.java:154) at
 android.app.ActivityThread.main(ActivityThread.java:6186) at
 java.lang.reflect.Method.invoke(Native Method)  at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

When forcing to call the deprecated FacebookSdk.sdkInitialize() in the application on create the following error occurs:

java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/facebook/common/R$layout;                    at
com.facebook.FacebookActivity.onCreate(FacebookActivity.java:77)    
at android.app.Activity.performCreate(Activity.java:6684)    at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)

P.S: I get an error when trying to use the Facebook login button

Error inflating class com.facebook.login.widget.LoginButton

Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50
Peter Helmy
  • 93
  • 2
  • 7

2 Answers2

3

Just a reminder, if one do define like this

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

Not what is required in the https://developers.facebook.com/docs/android/getting-started

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

They will get

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

I meet this scenario in Facebook Share SDK 4.31.0

compile 'com.facebook.android:facebook-share:4.31.0'
Francis Bacon
  • 4,080
  • 1
  • 37
  • 48
  • This worked for me, after trying different solutions for like 4 hours. Still, I don't get why setting the value directly doesn't work.. – adi.neag Mar 29 '18 at 19:53
1

This issue generally occurs when you forget to add the Facebook app id in the manifest file.

Follow these steps to make sure that you do not miss something.

Facebook Login for Android - Quickstart

Ali Asadi
  • 987
  • 10
  • 13
  • I followed the steps from that guide and the Facebook app id is enlisted in the manifest – Peter Helmy Jan 31 '18 at 13:13
  • The initialization: FacebookSdk.sdkInitialize(getApplicationContext()); should be done before setting the content view. If you do: setContentView(R.layout.activity_main); before the initialization, the Facebook button won't be inflated into the activity. – Ali Asadi Jan 31 '18 at 13:41
  • 1
    FacebookSdk.sdkInitialize(getApplicationContext()) is deprecated and should not be called in the latest SDK – Peter Helmy Jan 31 '18 at 13:54