简体   繁体   中英

InflateException while login with facebook using firebase in android

I want to login facebook with firebase in my android app, so after connecting my app with firebase I have added the dependency of facebook sdk compile 'com.facebook.android:facebook-android-sdk:[4,5)' but when I run my app then it shows

android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class com.facebook.login.widget.LoginButton

XML Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.environer.becofriend.MainActivity"
android:orientation="vertical"
android:gravity="center">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.facebook.login.widget.LoginButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>

Note: I have not added any code in my MainActivity because the sdk is initialized automatically in new sdk

Try this, I think changing the grade will do the work, I Have working example

1) Gradle

compile 'com.facebook.android:facebook-android-sdk:4.0.0'

2) XML

<com.facebook.login.widget.LoginButton
                    android:background="@drawable/login_button_back_one"
                    android:id="@+id/login_button"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

3) Java

    private AccessTokenTracker accessTokenTracker;
    private ProfileTracker profileTracker;
    private CallbackManager callbackManager; 
    LoginButton loginButton;

 FacebookSdk.sdkInitialize(ActivityName.this);

        loginButton = (LoginButton) findViewById(R.id.login_button);


        callbackManager = CallbackManager.Factory.create();

        accessTokenTracker= new AccessTokenTracker() {
            @Override
            protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {

            }
        };
 accessTokenTracker.startTracking();

 private void displayMessage(Profile profile){
        if(profile != null){
            Log.v("@@@WWE"," "+profile);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM