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

This is the error i'm getting when setting up CircleCI with Android my app. II think it is because I don't have the Google-Services.json file in my repo! But I can't upload it for security purposes. What could be the best alternative way around to fix this issue?

Sachin Titus
  • 1,960
  • 3
  • 23
  • 41
  • Possible duplicate of [Adding Google-services.json for CircleCI to function, on a public repository](https://stackoverflow.com/questions/50671196/adding-google-services-json-for-circleci-to-function-on-a-public-repository) – Vadim Kotov Oct 21 '19 at 11:56

1 Answers1

1

I ran into the exact same thing and here are the steps I did to solve it.

  1. Take the contents of your google-services.json and base64 encode them. You can do it in powershell like so:

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

    or use a website like this: https://www.base64encode.org/

  2. Add an environment variable to your CircleCI project where the value of the key is the base64 encoded string from step 1. like so:enter image description here

  3. In your CircleCI congfig.yml add the following commands, preferable near the top:

    - 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
    

From there you can trigger a build normally and it will work. What this is basically doing is storing your json in a safe private manner that avoids checking it into version control. It exports the base64 encoded CircleCI variable into bash variables that are available to the build server. From there it decodes it into a file in the location specified in the end of the decode command. This is the place google documentation tells you to place it. Here is a link to the documentation: Firebase Docs

Something to note:

  1. If the contents of your google-services.json changes then you will have to re-upload the string like in step 1.
stegnerd
  • 1,119
  • 1
  • 17
  • 25