Android - Facebook SDK 4.30 Initialization
Asked Answered
A

2

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

Alainaalaine answered 31/1, 2018 at 11:54 Comment(6)
Add this line before button click FacebookSdk.sdkInitialize().Wickiup
Post the full error logCircumstance
@Shivan FacebookSdk.sdkInitialize()is deprecatedAlainaalaine
Your problem has already been solved here.Instinct
@gendkidesuka no it'haven'tAlainaalaine
For next one come to here: https://mcmap.net/q/293376/-facebook-sdk-has-not-been-initialized-facebooksdk-sdkinitializeEarleanearleen
D
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'
Discard answered 13/3, 2018 at 10:52 Comment(1)
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..Bobbee
P
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

Pretense answered 31/1, 2018 at 12:38 Comment(3)
I followed the steps from that guide and the Facebook app id is enlisted in the manifestAlainaalaine
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.Pretense
FacebookSdk.sdkInitialize(getApplicationContext()) is deprecated and should not be called in the latest SDKAlainaalaine

© 2022 - 2024 — McMap. All rights reserved.