I am using firebase UI login into my app but when i use Facebook builder it stops the app how to inflate that button..?

[亡魂溺海] 提交于 2020-05-17 06:57:53

问题


i am enclosing the code of the Java file, dependency file and Manifestfile

i declared outside

 private static final int MY_REQUEST_CODE = 123;
    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.PhoneBuilder().build(),
            new AuthUI.IdpConfig.FacebookBuilder().build(),
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().build(),
            new AuthUI.IdpConfig.TwitterBuilder().build());

after this i mentioned this

 Intent intent = AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setAvailableProviders(providers)
                .setLogo(R.drawable.logo)
                .setTheme(R.style.LoginTheme)
                .setTosAndPrivacyPolicyUrls(
                                        "https://example.com/terms.html",
                                "https://example.com/privacy.html")
                .build();

and the last i mention the startActivity

startActivityForResult(intent,MY_REQUEST_CODE);

now this is my Dependencies File

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'  //1.0.2
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    //Firebase
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'

    //Facebook
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    implementation 'com.facebook.android:facebook-android-sdk:5.15.1'

    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.google.firebase:firebase-auth:19.3.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    //Cardview and Material
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.1.0' //1.1.0

    //button
    implementation 'info.hoang8f:fbutton:1.0.5'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
}

after this it is my Manifest file

  <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".Geo_Activity"/>
        <activity android:name=".Profile" />
        <activity android:name=".HomeActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <meta-data android:name="com.facebook.sdk.ApplicationId"
            tools:replace="android:value"
            android:value="@string/facebook_app_id" />

        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

    </application>

now the problem is that when I add the Facebuilder().build() line into my array list the app is crashed

this is the output screen


回答1:


Change your dependencies to :

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'  //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'

//Facebook

implementation 'com.facebook.android:facebook-android-sdk:5.15.1'



testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0

//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'

Edit :

Add these two strng resources to your strngs :

    <string name="facebook_application_id" translatable="false">APP_ID</string>
<!-- Facebook Application ID, prefixed by 'fb'. Enables Chrome Custom tabs. -->
<string name="facebook_login_protocol_scheme" translatable="false">fbAPP_ID</string>

If you run the app, It will work now, but clicking the facebook button won't get the user authenticated until you get the app id and scheme

To get the app id, log into your facebook account, visit the developers page https://developers.facebook.com/ Create an app there, then add the 'facebook login' and then follow the instructions given. You will find your app id in the top of the page of your facebook app

Just two notes :

  • You need copy the 'OAuth Redirect URI' from the firebase console page(the link given when enabling facebook authentication) to the settings of your facebook app

  • You will need the 'Key hash' which you can be obtained as described here https://stackoverflow.com/a/25524657/9006761 You will then copy it to your facebook app settings

Edit : Scheme is just app id prefixed by 'fb'



来源:https://stackoverflow.com/questions/61373084/i-am-using-firebase-ui-login-into-my-app-but-when-i-use-facebook-builder-it-stop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!