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

如何排查发布版Flutter应用App Check完整性验证失败问题

问题解答

1. 在发布版真机中获取并展示IntegrityErrorCode

Flutter的Firebase App Check在验证失败时会抛出FirebaseAppCheckException,其中的code字段对应Android平台的IntegrityErrorCode。你需要在调用受App Check保护的Firebase服务(比如Firestore读写)时捕获该异常,提取错误码并展示给用户。

示例代码:

try {
  // 调用受保护的Firebase操作,比如Firestore查询
  await FirebaseFirestore.instance.collection('data').get();
} on FirebaseAppCheckException catch (e) {
  // 获取对应的错误码
  final errorCode = e.code;
  // 根据错误码给用户展示提示,比如弹窗或文本
  showDialog(
    context: context,
    builder: (context) => AlertDialog(
      title: const Text('验证失败'),
      content: Text('错误码:$errorCode'),
      actions: [TextButton(onPressed: () => Navigator.pop(context), child: const Text('确定'))],
    ),
  );
}

常见的Play Integrity相关错误码包括:

  • playIntegrityApiConnectionError:与Play Integrity服务连接失败
  • playIntegrityApiQuotaExceeded:Play Integrity API调用配额超限
  • playIntegrityInvalidRequest:请求参数无效
  • playIntegrityTokenExpired:验证令牌过期
  • playIntegrityTokenInvalid:验证令牌无效

2. 查看App Check验证失败的日志及原因

可以在Firebase控制台和Google Cloud中查看相关日志:

Firebase控制台

  1. 打开Firebase控制台,进入你的项目
  2. 导航到App Check页面
  3. 切换到监控标签,这里会展示App Check的验证请求统计,包括失败请求的数量和趋势
  4. 点击具体的失败条目,可查看错误类型和对应的请求详情

Google Cloud Logging

  1. 打开Google Cloud控制台,进入你的项目
  2. 导航到Logging > 日志浏览器
  3. 使用以下查询语句过滤App Check相关的失败日志:
resource.type="firebase_project"
logName="projects/[你的项目ID]/logs/firebase.appcheck"
severity="ERROR"

查询结果中会包含失败的具体原因,比如错误码、请求来源、时间戳等信息,帮助定位问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 11:37:15