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

Flutter集成Firebase Auth调用signInWithCredential时iOS端崩溃(NSException)

iOS Flutter Firebase Auth崩溃:NSInternalInconsistencyException在PigeonAuthCredential断言失败

调用Firebase Auth的signInWithCredential时应用崩溃,Flutter层面仅显示"Lost connection to device",Xcode捕获到断言失败异常:

*** Assertion failure in +[PigeonAuthCredential fromList:], firebase_auth_messages.g.m:372
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ''

问题根源

核心原因是依赖版本不兼容:手动在dependency_overrides中指定的firebase_auth_platform_interface: ^6.13.0与firebase_auth: ^4.6.0版本不匹配,导致Flutter与原生iOS之间的Pigeon序列化机制出错,无法正确解析AuthCredential对象。

解决步骤

1. 移除不兼容的依赖覆盖

删除pubspec.yaml中的dependency_overrides下的firebase_auth_platform_interface配置,让firebase_auth自动使用其依赖的兼容版本:

# 移除以下内容
dependency_overrides:
  firebase_auth_platform_interface: ^6.13.0

2. 升级Firebase相关依赖到兼容版本

更新pubspec.yaml中的Firebase依赖到最新兼容版本(版本号可根据实际情况调整,确保互相兼容):

firebase_core: ^2.24.0
firebase_auth: ^4.12.0
google_sign_in: ^6.2.1
flutter_facebook_auth: ^7.2.0

执行依赖更新:

flutter pub get

3. 清理iOS构建缓存

在项目根目录执行:

flutter clean

进入iOS目录,删除Pod缓存:

cd ios
rm -rf Pods Podfile.lock
pod install

重启Xcode和模拟器,重新构建项目。

4. 验证Credential创建逻辑

确保第三方登录的Credential对象正确创建:

  • Google登录:
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
if (googleUser != null) {
  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
  final OAuthCredential credential = GoogleAuthProvider.credential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );
  final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
}
  • Facebook登录:
final LoginResult result = await FacebookAuth.instance.login();
if (result.status == LoginStatus.success) {
  final OAuthCredential credential = FacebookAuthProvider.credential(result.accessToken!.token);
  final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
}

5. 额外验证项

  • 检查GoogleService-Info.plist是否正确添加到Xcode项目中,且配置信息与Firebase控制台一致
  • 确认Info.plist中已添加Google和Facebook的URL Scheme
  • 尝试使用真实iOS设备测试,排除模拟器环境问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 08:42:25