FirebaseUI 身份验证在 android 上崩溃

Posted

技术标签:

【中文标题】FirebaseUI 身份验证在 android 上崩溃【英文标题】:FirebaseUI auth is crashing on android 【发布时间】:2016-11-04 12:17:14 【问题描述】:

我正在尝试使用新的FirebaseUI 进行身份验证。我在 LogCat 中收到以下错误

07-01 22:33:17.170 715-789/com.gmail.rixx.justin.cashcaddy I/OpenGLRenderer: Initialized EGL, version 1.4
07-01 22:33:17.234 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zzf>
07-01 22:33:17.235 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zzf>
07-01 22:33:17.242 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$3>
07-01 22:33:17.242 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$3>
07-01 22:33:17.243 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zzf>
07-01 22:33:17.243 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$4>
07-01 22:33:17.243 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$4>
07-01 22:33:17.244 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zzf>
07-01 22:33:17.244 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$1>
07-01 22:33:17.245 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$1>
07-01 22:33:17.245 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zzf>
07-01 22:33:17.246 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$2>
07-01 22:33:17.246 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.credentials.internal.zze$2>
07-01 22:33:17.247 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.zzc$zza>
07-01 22:33:17.247 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.zzc$zza>
07-01 22:33:17.248 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.zzc$1>
07-01 22:33:17.248 715-715/com.gmail.rixx.justin.cashcaddy I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.auth.api.signin.internal.zzc$1>
07-01 22:33:17.251 715-715/com.gmail.rixx.justin.cashcaddy D/AndroidRuntime: Shutting down VM
07-01 22:33:17.259 715-715/com.gmail.rixx.justin.cashcaddy E/UncaughtException: java.lang.NoSuchMethodError: No virtual method zztw()Ljava/util/Set; in class Lcom/google/android/gms/common/internal/zzg; or its super classes (declaration of 'com.google.android.gms.common.internal.zzg' appears in /data/app/com.gmail.rixx.justin.cashcaddy-2/base.apk)
                                                                                at com.google.android.gms.auth.api.signin.internal.zzd.<init>(Unknown Source)
                                                                                at com.google.android.gms.auth.api.Auth$4.zza(Unknown Source)
                                                                                at com.google.android.gms.auth.api.Auth$4.zza(Unknown Source)
                                                                                at com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown Source)
                                                                                at com.google.android.gms.common.api.GoogleApiClient$Builder.zzaof(Unknown Source)
                                                                                at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
                                                                                at com.firebase.ui.auth.util.CredentialsAPI.initGoogleApiClient(CredentialsAPI.java:148)
                                                                                at com.firebase.ui.auth.util.CredentialsAPI.<init>(CredentialsAPI.java:64)
                                                                                at com.firebase.ui.auth.ui.ChooseAccountActivity.onCreate(ChooseAccountActivity.java:64)
                                                                                at android.app.Activity.performCreate(Activity.java:6251)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5422)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-01 22:33:17.261 715-773/com.gmail.rixx.justin.cashcaddy I/FA: Tag Manager is not found and thus will not be used
07-01 22:33:17.481 715-715/com.gmail.rixx.justin.cashcaddy D/FirebaseCrashApiImpl: throwable java.lang.NoSuchMethodError: No virtual method zztw()Ljava/util/Set; in class Lcom/google/android/gms/common/internal/zzg; or its super classes (declaration of 'com.google.android.gms.common.internal.zzg' appears in /data/app/com.gmail.rixx.justin.cashcaddy-2/base.apk)
07-01 22:33:17.517 715-715/com.gmail.rixx.justin.cashcaddy E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.gmail.rixx.justin.cashcaddy, PID: 715
                                                                         java.lang.NoSuchMethodError: No virtual method zztw()Ljava/util/Set; in class Lcom/google/android/gms/common/internal/zzg; or its super classes (declaration of 'com.google.android.gms.common.internal.zzg' appears in /data/app/com.gmail.rixx.justin.cashcaddy-2/base.apk)
                                                                             at com.google.android.gms.auth.api.signin.internal.zzd.<init>(Unknown Source)
                                                                             at com.google.android.gms.auth.api.Auth$4.zza(Unknown Source)
                                                                             at com.google.android.gms.auth.api.Auth$4.zza(Unknown Source)
                                                                             at com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown Source)
                                                                             at com.google.android.gms.common.api.GoogleApiClient$Builder.zzaof(Unknown Source)
                                                                             at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
                                                                             at com.firebase.ui.auth.util.CredentialsAPI.initGoogleApiClient(CredentialsAPI.java:148)
                                                                             at com.firebase.ui.auth.util.CredentialsAPI.<init>(CredentialsAPI.java:64)
                                                                             at com.firebase.ui.auth.ui.ChooseAccountActivity.onCreate(ChooseAccountActivity.java:64)
                                                                             at android.app.Activity.performCreate(Activity.java:6251)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                             at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5422)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我正在 onCreate 中启动身份验证请求:

    FirebaseAuth auth = FirebaseAuth.getInstance();
    if (auth.getCurrentUser() != null) 
        // already signed in
        Toast.makeText(this, "Signed in!", Toast.LENGTH_LONG).show();
     else 
        startActivityForResult(
                // Get an instance of AuthUI based on the default app
                AuthUI.getInstance().createSignInIntentBuilder().build(),
                RC_SIGN_IN);
        Toast.makeText(this, "Not signed in", Toast.LENGTH_LONG).show();
    

并在 onActivityResult 中接受结果

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) 
        if (resultCode == RESULT_OK) 
            // user is signed in
            Toast.makeText(this, "Signed in!", Toast.LENGTH_LONG).show();
         else 
            // user is not signed in. Maybe just wait for the user to press
            // "sign in" again, or show a message
            Toast.makeText(this, "Not signed in!", Toast.LENGTH_LONG).show();
        
    

我认为我已经正确设置了它。我下载了我的 google-services.json 并放在我的 app/ 目录中。 这是我的项目build.gradle

buildscript 
    repositories 
        jcenter()
    
    dependencies 
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
    


allprojects 
    repositories 
        jcenter()
    


task clean(type: Delete) 
    delete rootProject.buildDir

和我的应用程序 gradle 文件

apply plugin: 'com.android.application'

android 
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig 
        applicationId "com.gmail.rixx.justin.cashcaddy"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    


dependencies 
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-database:9.2.0'
    compile 'com.google.firebase:firebase-auth:9.2.0'
    compile 'com.google.firebase:firebase-crash:9.2.0'
    compile 'com.firebaseui:firebase-ui:0.4.1'


apply plugin: 'com.google.gms.google-services'

当应用程序打开时,崩溃就发生了,我认为这只是我的一个配置的一些小问题。

谢谢

【问题讨论】:

您是否在控制台上的 Firebase 项目中启用了登录方法? 是的。我有一个成功使用电子邮件和密码的网络应用程序。 你能分享你的 app.gradle 吗? 我认为您在此处粘贴的崩溃日志不是您实际错误的原因,请仔细查看崩溃日志并尝试找到真正的原因。如果您在日志中发现其他内容。一定要在这里分享..!! 我从旧的 Firebase 升级时遇到了类似的问题。看看它也许可以解决你的问题:***.com/questions/37360126/… 【参考方案1】:

Android 版 Firebase UI 的 0.4.2 版本刚刚发布,它包含解决此问题所需的基础更改。

【讨论】:

【参考方案2】:

我也有同样的问题。这似乎是从一个构建到另一个构建发生的,这很奇怪。

由于错误消息抱怨缺少 gms 内容,因此为我解决的问题是在我的依赖项中添加以下内容:

compile 'com.google.android.gms:play-services-auth:9.2.0'

我相信这应该已经是 Firebase Auth 库的依赖项,所以我猜这是某种错误。

【讨论】:

太棒了!这对我有用!当我将该依赖项添加到 gradle 关于混合 google 服务版本时出现错误,但是当我进行 gradle 构建时它就消失了。

以上是关于FirebaseUI 身份验证在 android 上崩溃的主要内容,如果未能解决你的问题,请参考以下文章

FirebaseUI for Web — 身份验证 — 如何重新进行身份验证?

Firebase Auth 与 firebaseui-web 在身份验证后不会重定向

Android FirebaseUI 登录时使用 Google 错误获取发布密钥

Android.FirebaseUI-Android:由于异常活动,我们已阻止来自此设备的所有请求

哪个定价层提到 Firebase 身份验证?

将 FirebaseUI 与 Twitter 登录一起使用(iOS 应用)