Android Studio Google登录报错:getCredentialAsync无依赖提供者
解决Credential Manager Google登录错误:
getCredentialAsync no provider dependencies found 核心问题分析
你遇到的getCredentialAsync no provider dependencies found错误,大概率和两个因素直接相关:模拟器Google Play服务版本过旧,以及依赖配置存在冲突或缺失。
1. 先解决Google Play服务过期警告
模拟器提示的Requires 230815045 but found 201817022是关键诱因:Credential Manager的Google登录实现依赖新版Play服务提供的认证模块,旧版本Play服务无法识别你配置的GetGoogleIdOption,直接导致找不到提供者。
解决方法:
- 更新模拟器Play服务:打开模拟器内的「Play商店」,进入个人资料页 → 「设置」→ 「关于」,点击「Play服务版本」检查并手动更新,更新后重启模拟器。
- 使用新版模拟器镜像:在AVD管理器中创建新模拟器,选择带有「Google Play」标记的系统镜像(优先选API 33/34+的最新版本),这类镜像自带最新Play服务。
- 优先用真实设备测试:真实设备的Play服务通常会自动更新,能避开模拟器的版本滞后问题。
2. 清理依赖冲突
你的依赖中存在潜在冲突,firebase-ui-auth库自带了旧版的Google认证依赖,会和你手动引入的play-services-auth、Credential Manager依赖冲突,导致提供者无法正常注册。
修改后的依赖配置(移除冲突项)
implementation(platform("com.google.firebase:firebase-bom:33.4.0")) implementation("com.google.firebase:firebase-auth") implementation("com.google.firebase:firebase-database") implementation("com.google.firebase:firebase-firestore") implementation("com.google.accompanist:accompanist-permissions:0.34.0") implementation("com.google.firebase:firebase-auth-ktx") // Authentication with Credential Manager implementation("androidx.credentials:credentials:1.3.0") implementation("androidx.credentials:credentials-play-services-auth:1.3.0") implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1") implementation("com.google.android.gms:play-services-auth:21.2.0") // 升级协程版本到稳定版 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
后续操作
- 执行
File → Invalidate Caches... → Invalidate and Restart清理Android Studio缓存 - 运行
./gradlew clean build命令重新构建项目,确保依赖完全同步
3. 代码优化(避免潜在问题)
虽然不是当前错误的直接原因,但可以优化代码减少后续隐患:
- 简化Nonce生成:Google提供了现成的工具方法生成符合要求的nonce,无需手动哈希:
val rawNonce = GoogleIdTokenCredential.generateNonce() val googleIdOption = GetGoogleIdOption.Builder() .setFilterByAuthorizedAccounts(false) .setServerClientId(ClientID) .setNonce(rawNonce) .build() - 验证ClientID正确性:确保
ClientID是Google API控制台中生成的Web客户端ID(不是Android客户端ID),可在Firebase控制台「Authentication → 登录方式 → Google」中查看。
4. 额外检查
- 确认AndroidManifest.xml中添加了网络权限:
<uses-permission android:name="android.permission.INTERNET" /> - 检查Firebase控制台已启用Google登录方式,且OAuth客户端ID配置正确。
内容的提问来源于stack exchange,提问作者hrishikesh deoghare
相关产品推荐
相关产品推荐

