GoogleService-Info.plist文件未找到,且未通过程序提供clientId。

8

我尝试使用 Flutterfire 命令行工具将 Firebase 添加到我的 Flutter 项目中。我正在使用 Firebase 的 Google 验证服务,并调用 SignIn 函数,但它报错了。ios 文件夹中有 GoogleService-Info.plist 文件。

Unhandled Exception: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
    <asynchronous suspension>
    #2      GoogleSignInPlatform.initWithParams (package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart:98:5)
    <asynchronous suspension>
    #3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:267:5)
    <asynchronous suspension>
    #4      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:402:5)

我也有同样的问题,我应该怎样解决? - Peshraw Hasan
你是否正在使用 flutterfire 命令行工具连接到 firebase?请参考已接受的答案。 - ASAD HAMEED
3个回答

12
FlutterFire 命令行工具会生成一个Dart文件,因此您不需要使用GoogleService-Info.plist。虽然使用命令行工具时插入 GoogleService-Info.plist 是多余的,但在初始化时必须指定生成的选项。
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)

使用DefaultFirebaseOptions是使用Flutter和Firebase的新方式,手动插入配置文件是旧方式.
编辑:我没有理解这个问题与GoogleSignIn插件有关(我没有真正阅读堆栈跟踪)。在这种情况下,错误与错误消息中完全相同。您尚未指定客户端ID:
GoogleSignIn(clientId: DefaultFirebaseOptions.currentPlatform.iosClientId).signIn()

编辑: 是的,新版本的flutterfire也会生成相应的文件,例如GoogleService-Info.plist,但是您不再需要这些文件,因为参数clientId已经存在于GoogleSignIn插件中。


1
我知道使用命令行工具不需要手动添加,但自动生成的文件无法正常工作,并出现了上述异常。 - ASAD HAMEED
现在明白了。但令人困惑的是,flutterfire 还会将 GoogleService-Info.plist 文件添加到 ios/Runner 目录下。 - ASAD HAMEED
确定吗?FlutterFire 不应该这样做。我的项目中没有 GoogleService-Info.plist 文件,而我正在使用 FlutterFire。 - Mäddin
是的,这就是让我感到困惑的地方,所以我决定在跟踪Github上类似问题后手动添加它。 - ASAD HAMEED
由于某些原因,我的 DefaultFirebaseOptions.currentPlatform.iosClientIdGoogleService-Info.plist 中找到的 CLIENT_ID 不匹配 - 我需要硬编码 GoogleSignIn(clientId: "key") - polonski

1
将GoogleService-Info.plist文件移动到Runner文件夹中解决了我的问题。

1

有人在Github上发布了一个问题。

https://github.com/flutter/flutter/issues/96248

他们说:

google_sign_in插件目前不支持仅使用Dart进行初始化,暂时您需要手动安装。

截止2022年8月31日,我仍然面临同样的问题。


1
我通过阅读文档并修改 [my_project]/ios/Runner/Info.plist 文件来解决了这个问题。 - millerf
@millerf,你是如何解决这个问题的?能否请您提供一些细节呢? - msalihbindak
@msalihbindak 我不太记得细节了,但基本上我把所有的东西都刮掉了,一行一行地按照flutter_google_signin文档进行了操作... - millerf
@msalihbindak 尽管我按照所有步骤操作,但我仍然遇到了同样的问题。原来是因为我的 GoogleService-Info.plist 没有针对 Runner 进行设置。也就是说,你只需要在 Xcode 中选择文件树中的 GoogleService-Info.plist,并将目标 Runner 标志放置在右侧即可。 - Siarhei Dudko

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接