I try to test the login with facebook SDK.
So I add with compile 'com.facebook.android:facebook-android-sdk:4.0.0'
.
Then add FacebookSdk.sdkInitialize(getApplicationContext());
to MainActivity.java
But when I add
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />`
I have this following error :
Rendering Problems The following classes could not be instantiated:
com.facebook.login.widget.LoginButton (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
Exception Details java.lang.NoClassDefFoundError: Could not initialize class com.facebook.login.widget.LoginButton
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385) Copy stack to clipboard
Simply specifying a different version of Facebook SDK worked for me.
Adjust the build.graddle
file dependencies part.
Mine looks like;
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.4.0'}
Version 4.0.0 persistently threw the exception
I did not have to import the Facebook SDK as a module
I had to play around with the different versions of the SDK as available here
You didn't posted your Activity code. But i think your code is like:
setContentView(R.layout.my_login_layout);
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create();
The problem is the order of the code. Ignore the "Render problems" in the layout, change the order of the code to this:
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create(); // this line doesn't matter
setContentView(R.layout.my_login_layout);
Use this code in OnCreate(...) { ... }
Avoid layout render problems
if you want to solve the render problems (layout preview) check the @Nathan30 answer (see below).
<com.facebook.widget.LoginButton .../>
to your layout.Simple, quick and easy: update the SDK version on Gradle
-> Dependencies
to the latest version and the rendering problem is solved. At the time of writing this, the latest Facebook SDK is 4.3.0, so this is what it should look like on Dependencies
:
compile 'com.facebook.android:facebook-android-sdk:4.3.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With