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

时间:2018-06-03 02:24:24

标签: android continuous-integration continuous-deployment google-play-services circleci-2.0

> #!/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 my app设置CircleCI时遇到的错误。我认为这是因为我的回购中没有Google-Services.json文件!但出于安全考虑,我无法上传它。什么是解决此问题的最佳替代方法?

1 个答案:

答案 0 :(得分: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编码的字符串。例如:enter image description here

  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文档告诉您的放置位置。这是文档的链接:Firebase Docs

注意事项:

  1. 如果您的google-services.json的内容发生了变化,则您将必须像步骤1中一样重新上传字符串。