我正在尝试在我的应用中添加FirebaseUI身份验证,但我很难坚持使用它。我在我的应用中添加了脸书,推特和电话号码验证,但它给了我错误:Cannot resolve method setAvailableProviders
和Cannot resolve symbol IdpConfig
。我应该怎么做我的应用程序来克服这个错误?你可以在图像中看到我有错误和红线。
这是我的manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anonymous.userlogin">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
这是我的gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.anonymous.userlogin"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
//android authentication dependicies.
compile 'com.google.firebase:firebase-auth:10.0.1'
//android login with fb tw ph user nterface dependices
compile 'com.firebaseui:firebase-ui-auth:0.6.0'
//compile 'com.firebaseui:firebase-ui-auth:3.0.0'
//facebook dependicies
compile 'com.facebook.android:facebook-login:4.27.0'
//twitter dependicies
compile("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true }
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.0.0-alpha1'
}
}
}
}
这是我的主要活动的代码
package com.example.anonymous.userlogin;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.firebase.ui.auth.AuthUI;
import com.google.firebase.auth.FirebaseAuth;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
private static final int RC_SIGN_IN = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null)
{}
else
{
// not signed in
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(
Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build()))
.build(),
RC_SIGN_IN);
}
}
}
这是标记错误的屏幕截图:
答案 0 :(得分:0)
您正在使用版本0.6.0的FirebaseUI Auth(com.firebaseui:firebase-ui-auth
),它没有此功能。您应该使用版本2.x或3.x。
在您应用的build.gradle
文件中更改此内容:
compile 'com.firebaseui:firebase-ui-auth:0.6.0'
//compile 'com.firebaseui:firebase-ui-auth:3.0.0'
对此:
compile 'com.firebaseui:firebase-ui-auth:3.0.0'
答案 1 :(得分:0)
从此更改依赖性版本:
compile 'com.firebaseui:firebase-ui-auth:0.6.0'
对此:
implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
并同步您的项目