Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Facebook SDK 4.30 Initialization

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

like image 729
Peter Helmy Avatar asked Jan 31 '18 11:01

Peter Helmy


Video Answer


2 Answers

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'
like image 104
Francis Bacon Avatar answered Oct 05 '22 03:10

Francis Bacon


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

like image 35
Ali Asadi Avatar answered Oct 05 '22 03:10

Ali Asadi