Error inflating class com.facebook.widget.LoginButton with Facebook SDK 4.0.1
Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
Make sure you initialized facebook SDK before setContentView.
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
Don't forget to added the android app id in the android manifest inside the application xml tag
<application>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
</application>
Only add this methods of your app's Application class::
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
Befeore: setContentView in onCreate Activity.
In dependencies import:
compile 'com.facebook.android:facebook-android-sdk:[4,5)' or smaller
Enjoy :)
In facebook sdk 4.0.1, LoginButton
class is not inside com.facebook.widget
package. It is inside com.facebook.login.widget
package. So your xml declaration should look like this:
<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" />