You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

平板模拟器上FirebaseUI身份验证功能异常求助

FirebaseUI邮箱身份验证在平板模拟器异常报错求助

我正尝试在Android应用中使用FirebaseUI实现用户邮箱身份验证,手机模拟器及真机上验证功能均正常运行,但平板模拟器进入登录界面时持续报错。

报错信息

E/AuthenticationActivity: Sign-in error: com.firebase.ui.auth.FirebaseUiException: Exception serialization error, forced wrapping. Original: com.firebase.ui.auth.FirebaseUiException: Play Services update cancelled, original cause: com.google.android.gms.common.api.ApiException: 9: Error connecting to Google Play services

依赖配置

模块级build.gradle

implementation(platform("com.google.firebase:firebase-bom:31.2.3"))
implementation("com.firebaseui:firebase-ui-auth:8.0.2")

项目级build.gradle

classpath("com.google.gms:google-services:4.3.15")

核心代码

import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.ErrorCodes
import com.firebase.ui.auth.FirebaseAuthUIActivityResultContract
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.auth.FirebaseAuth
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

@AndroidEntryPoint
class AuthenticationActivity : AppCompatActivity() {
    private val viewModel: AuthenticationViewModel by viewModels()

    private val signInLauncher = registerForActivityResult(
        FirebaseAuthUIActivityResultContract()
    ) { res ->
        this.onSignInResult(res)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModel.apply {
            ldSnackbarMessage.observe(this@AuthenticationActivity) {
                showSnackbarMessage(it)
            }
        }

        createSignInIntent()
    }

    override fun onDestroy() {
        super.onDestroy()

        viewModel.apply {
            ldSnackbarMessage.removeObservers(this@AuthenticationActivity)
        }
    }

    private fun createSignInIntent() {
        // [START auth_fui_create_intent]
        // Choose authentication providers
        val providers = arrayListOf(
            AuthUI.IdpConfig.EmailBuilder().build()
        )

        // Create and launch sign-in intent
        val signInIntent = AuthUI.getInstance()
            .createSignInIntentBuilder()
            .setAvailableProviders(providers)
            .setIsSmartLockEnabled(!BuildConfig.DEBUG /* credentials */, true /* hints */)
            .setTheme(R.style.AppTheme)
            .build()

        signInLauncher.launch(signInIntent)
        // [END auth_fui_create_intent]
    }

    // [START auth_fui_result]
    private fun onSignInResult(result: FirebaseAuthUIAuthenticationResult) {
        val response = result.idpResponse
        if (result.resultCode == RESULT_OK) {
            // Successfully signed in
            val user = FirebaseAuth.getInstance().currentUser
            viewModel.setUser(user) {
                finish()
            }
        } else {
            // Sign in failed
            if (response == null) {
                // User pressed back button
                showSnackbarMessage("Sign in canceled")
                finishAffinity()
            }

            if (response?.error?.errorCode == ErrorCodes.NO_NETWORK) {
                showSnackbarMessage("No internet connection!")
                finishAffinity()
            }

            showSnackbarMessage("Unknown error!")
            Timber.e("Sign-in error: ${response?.error}" )
        }
    }
    // [END auth_fui_result]

    private fun showSnackbarMessage(message: String) {
        if (message.isNotEmpty()) {
            val rootView = findViewById<View>(android.R.id.content)
            Snackbar.make(
                rootView,
                message,
                Snackbar.LENGTH_SHORT
            ).show()
        }
    }
}

设备与已尝试操作

  • 平板模拟器:Android 11系统
  • 手机模拟器:Android 11系统(功能正常)
  • 已执行操作:检查所有必要依赖、清理并重建项目,问题仍未解决

期望平板模拟器能实现与手机模拟器相同的登录界面效果。

内容的提问来源于stack exchange,提问作者Justin Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 10:14:55