2
> #!/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 文件!但出于安全考虑,我不能上传它。解决此问题的最佳替代方法是什么?

4

1 回答 1

1

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

  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 config.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 变量。从那里它将其解码为解码命令末尾指定位置的文件。这是谷歌文档告诉你放置它的地方。这是文档的链接:Firebase Docs

需要注意的一点:

  1. 如果您的 google-services.json 的内容发生变化,那么您将不得不像第 1 步中那样重新上传字符串。
于 2020-02-26T04:42:46.060 回答