1

I am currently working on a android project and I use github action to test the project. But whenever it build it ends up with an error for not finding the google-services.json file.

The error generated is as follows

File google-services.json is missing. The Google Services Plugin cannot function without it.

Now, I don't want to commit or upload the google-services.json file on the github. So, Is there any other way to solve this?

  • Never ever upload secrets to your repositories. You can define secure CI variables for that purpose. – Tobi Jan 03 '22 at 16:28
  • Although it's not so risky if anyone reverse engineer the app and sees them, you should not commit them to Github as mentioned by Firebase in the [documentation](https://firebase.google.com/docs/projects/learn-more#:~:text=we%20generally%20do%20not%20recommend%20including%20the%20app%27s%20Firebase%20config%20file). Also checkout: [Is google-services.json safe from hackers?](https://stackoverflow.com/questions/45508516/is-google-services-json-safe-from-hackers) – Dharmaraj Jan 03 '22 at 16:37
  • @Tobi Yeah actually it helped but doesn't give the proper way to do for github. But now I have figured out the solution : ) – Atul Sharma Jan 04 '22 at 07:23

2 Answers2

1

If you are making any public repo or any sample app, you should not commit the google-services.json file to the Github repo.

While you are working on private repo it depends on how collaborators are managing the firebase credentials. google-services.json file will have access key and fingerprints of firebase projects.

Conclusion: Don't share the google-services.json file over any SVN or Git repo. User can add their own google-services.json file to the project and run it on the testing environment.

Mayur Sojitra
  • 722
  • 7
  • 18
1

Well... I have found the solution but in case if anyone needs I am explaining here.

We can store the content of google-sevices.json in Environment variable (aka Secrets in github). Actually github uses linux based cli so we have to execute some command on the cli using github actions.

There will be two steps ...

  • Firstly create the google-services.json file in base64
- name: Create file
  run: cat /home/runner/work/<Project-Name>/<Project-Name>/app/google-services.json | base64
  • Then put data in the file (basically this fetch data from github secrets and put the data in json file before building the application)
- name: Putting data
  env:
    DATA: ${{ secrets.GOOGLE_SERVICES_JSON }}
  run: echo $DATA > /home/runner/work/<Project-Name>/<Project-Name>/app/google-services.json
  • Then define the content of google-services.json file in the github secrets via: Setting > Secrets > New Repository Secret using name GOOGLE_SERVICES_JSON

Both of these commands should be placed before the gradle build command in gradle.yml

By doing this your google-services.json file will be created and has data also so the app will build successfully.