通过Fastlane分发Firebase应用程序,“服务器响应状态403”

14

我在Fastlane Fastfile中设置了Firebase应用分发功能,以便分发我的iOS应用程序的测试版。它一直运行良好,但突然出现错误信息。

以下是我的代码:

lane :distribute_beta do |options|
        
        sync_code_signing_adhoc()
        update_build_number_of_all_frameworks() 
        build_ios_app_adhoc()

        firebase_app_distribution(
            app: "<app ID here>",
            testers: "<tester emials here>",
            release_notes: options[:release_note],
            firebase_cli_path: "/usr/local/bin/firebase"
        )
end  

当我运行此代码时,它显示错误。

the server responded with status 403

在步骤中:firebase_app_distribution

日志还显示成功认证到Google。

 Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
  Authenticated successfully.

以下是“步骤:firebase_app_distribution”的完整错误信息

[17:11:04]: ---------------------------------------
[17:11:04]: --- Step: firebase_app_distribution ---
[17:11:04]: ---------------------------------------
[17:11:04]: Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
[17:11:04]:  Authenticated successfully.
+------------------------------------+---------------------------------------------+
|                                   Lane Context                                   |
+------------------------------------+---------------------------------------------+
| DEFAULT_PLATFORM                   | ios                                         |
| PLATFORM_NAME                      | ios                                         |
| LANE_NAME                          | ios distribute_beta                         |
| SIGH_PROFILE_TYPE                  | ad-hoc                                      |
| MATCH_PROVISIONING_PROFILE_MAPPING | {"<my bndle ID>"=>"match AdHoc              |
|                                    | <my bundle ID>"}                            |
| BUILD_NUMBER                       | 107                                         |
| IPA_OUTPUT_PATH                    | /Users/my_user_name/Repository/App/App|
|                                    | y/App.ipa                                   |
| XCODEBUILD_ARCHIVE                 | /Users/my_user_name/Library/Developer/Xcode/A|
|                                    | rchives/2021-01-08/App 2021-01-08           |
|                                    | 17.09.08.xcarchive                          |
| DSYM_OUTPUT_PATH                   | /Users/my_user_name/Repository/App/App           |
|                                    | y/App.app.dSYM.zip                          |
+------------------------------------+---------------------------------------------+
[17:11:06]: the server responded with status 403

+------+-----------------------------+-------------+
|                 fastlane summary                 |
+------+-----------------------------+-------------+
| Step | Action                      | Time (in s) |
+------+-----------------------------+-------------+
| 1    | default_platform            | 0           |
| 2    | Switch to ios               | 0           |
|      | sync_code_signing_adhoc     |             |
|      | lane                        |             |
| 3    | sync_code_signing           | 18          |
| 4    | Switch to ios               | 0           |
|      | update_build_number_of_all  |             |
|      | _frameworks lane            |             |
| 5    | increment_build_number      | 1           |
| 6    | commit_version_bump         | 0           |
| 7    | Switch to ios               | 0           |
|      | build_ios_app_adhoc lane    |             |
| 8    | build_ios_app               | 126         |
|    | firebase_app_distribution   | 1           |
+------+-----------------------------+-------------+

[17:11:06]: fastlane finished with errors

我该怎么修复这个问题?

8个回答

16

通常情况下,当您收到那个特定的消息时,意味着 Firebase 刷新令牌已不再有效。

因此,在提交应用程序时,您必须指定 Firebase 刷新令牌:

...
firebase_app_distrubution(
  ...
  firebase_cli_token: "<YourFirebaseRefreshToken>"
)
...

你可以从这里获取此令牌。如果您的脚本突然出现故障,那很可能是生成此(或任何其他身份验证令牌)的人已从Firebase项目中删除。

如果您收到错误代码403,那肯定意味着有人已从Firebase项目中删除,或者有人在Firebase控制台上删除/重新生成了令牌。


我已经有一段时间没有运行beta部署代码了,所以我的刷新令牌可能已经过期了,我会检查一下。 - Bigair
1
如果您正在使用服务帐户进行 Firebase 认证,请确保此服务帐户具有“Firebase 应用分发管理员”角色。 - adjustment layer
还是不起作用。 - undefined

7
对我来说,这是因为我使用的服务帐户没有“Firebase App Distribution Admin”角色。 我只需编辑现有服务即可。要这样做,请转到Firebase控制台>项目设置>服务帐户>然后按下面图像所示单击服务帐户。 https://firebase.google.com/docs/app-distribution/authenticate-service-account?platform=ios

enter image description here

这将带您到GCP IAM和Admin页面,您可以在该页面找到并编辑您的服务账号的角色。


5
  1. Simply run the following command on console:

    curl -sL https://firebase.tools | bash
    
  2. then, authenticate on the browser

  3. Then run

    firebase login:ci
    
  4. After success you will get printed your new cli token, like this:

等待身份验证...
✔ 成功! 使用此令牌登录CI服务器:
1//这里将是您的新令牌
示例: firebase deploy --token "$FIREBASE_TOKEN"

很遗憾,这个方法不起作用。仍然收到403错误。 - undefined

0
对我来说,我必须将我用于应用程序分发登录的特定帐户添加到我的应用程序的项目设置中。

enter image description here


0

请确认您的 Firebase 帐户具有项目分发权限。 项目设置 -> 用户和权限 -> 成员应该拥有 "编辑者" 角色


0

另一件要检查的事情是确保您的应用程序 ID设置正确。 您可以在 Firebase 项目设置中找到它。

当您创建新的应用程序变体(例如开发 vs. 生产、验收等)并忘记更新 app_id 或 serviceAccount 文件时,可能会遇到此问题。


0

同时,请确保您使用适当的帐户登录(这是我错误的原因)。


0
我的Firebase App Distribution和Fastlane的经验与教程中所述的有些不同(https://developersancho.medium.com/ci-cd-firebase-app-distribution-with-fastlane-on-android-8ee419f770b7)。在教程中,它建议使用私有的JSON文件进行身份验证,但我在使用这种方法时遇到了一些挑战。以下是我解决问题的方法:
起初,我在Fastlane中使用了一个私有的JSON文件来配置Firebase App Distribution,就像这样:
firebase_app_distribution(
    app: ENV["FIREBASE_APP_ID"],
    apk_path: apk_path,
    release_notes: "#{release_note}",
    groups_file: "fastlane/groups.txt",
    service_credentials_file: ENV["FIREBASE_LOGIN_CREDENTIALS"]
)

然而,我发现私有的JSON文件方法对我来说不起作用。我尝试使用Firebase CLI进行身份验证,并使用令牌,正如其他答案所建议的(使用firebase_cli_token),但不幸的是,这也没有解决问题。
为了解决这个问题,我决定从我的Fastlane设置中移除私有JSON文件的使用,从而得到以下配置:
firebase_app_distribution(
    app: ENV["FIREBASE_APP_ID"],
    apk_path: apk_path,
    release_notes: "#{release_note}",
    groups_file: "fastlane/groups.txt"
)

在进行这个更改后,我遇到了Fastlane的一个错误消息,它表示找不到任何凭据。然而,有趣的是,它继续使用了“缓存的Firebase CLI凭据”,奇迹般地,分发过程成功了。

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