CircleCI 构建失败,因为 Google-Services.json 不存在

CircleCI build fails because Google-Services.json is not present

> #!/bin/bash -eo pipefail
./gradlew lint test
Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:mainApkListPersistenceDebug
:app:generateDebugResValues
:app:generateDebugResources
:app:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it. 
   Searched Location: 
  /home/circleci/code/app/src/nullnull/debug/google-services.json
  /home/circleci/code/app/src/debug/nullnull/google-services.json
  /home/circleci/code/app/src/nullnull/google-services.json
  /home/circleci/code/app/src/debug/google-services.json
  /home/circleci/code/app/src/nullnullDebug/google-services.json
  /home/circleci/code/app/google-services.json

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
9 actionable tasks: 9 executed
Exited with code 1

这是我在使用 Android 我的应用程序设置 CircleCI 时遇到的错误。我认为这是因为我的回购中没有 Google-Services.json 文件!但出于安全考虑,我不能上传它。解决此问题的最佳替代方法是什么?

我 运行 遇到了完全相同的事情,这是我解决它的步骤。

  1. 将你的google-services.json的内容进行base64编码。您可以像这样在 powershell 中执行此操作:

    PS C:\Temp>$s = [System.Text.Encoding]::UTF8.GetBytes("contents of file pasted here")
    PS C:\Temp>[System.Convert]::ToBase64String($s)
    

    或使用这样的网站:https://www.base64encode.org/

  2. 向您的 CircleCI 项目添加一个环境变量,其中键值是来自步骤 1 的 base64 编码字符串。像这样:

  3. 在您的 CircleCI congfig.yml 中添加以下命令,最好靠近顶部:

    - run:
        # Export base64 encoded google-services.json
        # into local bash variables
        name: Export Google Services Json
        command: echo 'export GOOGLE_SERVICES_JSON="$GOOGLE_SERVICES_JSON"' >> $BASH_ENV
    - run:
        # Decode the base64 string
        name: Decode Google Services Json
        command: echo $GOOGLE_SERVICES_JSON | base64 -di > app/google-services.json
    

从那里您可以正常触发构建,它会工作。这基本上是在以一种安全的私有方式存储您的 json,避免将其签入版本控制。它将 base64 编码的 CircleCI 变量导出为构建服务器可用的 bash 变量。它从那里将其解码到解码命令末尾指定位置的文件中。这是 google 文档告诉您放置它的地方。这是文档的 link:Firebase Docs

注意事项:

  1. 如果 google-services.json 的内容发生变化,那么您将不得不像步骤 1 中那样重新上传字符串。