【问题标题】:Firebase auth crash when initialize providers (Android)初始化提供程序时 Firebase 身份验证崩溃(Android)
【发布时间】:2020-05-19 08:03:33
【问题描述】:

我正在尝试通过 Firebase Auth 在我的应用中添加身份验证。 我遇到了一些问题,这里是代码:

private List<AuthUI.IdpConfig> providers;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    setContentView(R.layout.activity_main);

    providers = Arrays.asList(
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.PhoneBuilder().build(), <----- ERROR
            new AuthUI.IdpConfig.FacebookBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().build());
}

错误日志是这样的:

原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“java.lang.String android.content.Context.getString(int)”

这是我的 Gradle 依赖项:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.firebase:firebase-client-android:2.5.2'
}

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    移除以下依赖:

        implementation 'com.firebase:firebase-client-android:2.5.2'
    

    上面的依赖是很老的firebase依赖,这里需要检查一下:

    https://firebase.google.com/docs/android/setup

    了解如何设置 firebase 依赖项


    这似乎是一个新项目,所以迁移到androidx,然后使用以下firebaseui依赖:

    implementation 'com.firebaseui:firebase-ui-auth:6.2.1'
    

    https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md

    https://developer.android.com/jetpack/androidx/migrate

    【讨论】:

    • 我做了迁移,并编辑了 gradle: dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0- beta01' 执行 'androidx.constraintlayout:constraintlayout:1.1.3' 执行 'com.google.firebase:firebase-database:16.0.4' testImplementation 'junit:junit:4.12' 执行 'com.facebook.android:facebook-android- sdk:[4,5)' implementation 'com.firebaseui:firebase-ui-auth:6.2.1' } 错误是一样的。
    猜你喜欢
    • 2020-08-21
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 2018-10-31
    • 1970-01-01
    相关资源
    最近更新 更多