The google-services plugin has two main functions:
Process the google-services.json file and produce Android resources that can be used in your application’s code.
Add dependencies for basic libraries required for the services you have enabled. This step requires that you apply the Google Services Gradle plugin in your app/build.gradle file, like so:
apply plugin: ‘com.google.gms.google-services’
And to answer your question:
Is there a way to load google-services.json from an API rather than copying it to the project?
No, you cannot. You have to explicitly add the file to the project’s app directory. Alternatively, you can use product flavors when you have to use more complicated directory structures:
// free and paid are product flavors.
app/
google-services.json
src/dogfood/paid/google-services.json
src/release/free/google-services.json
2
Answers
This is not possible because the initialisation of Google libraries is internal and it expects to read client information from this file.
According to the official documentation regarding The Google Services Gradle Plugin:
And to answer your question:
No, you cannot. You have to explicitly add the file to the project’s
app
directory. Alternatively, you can use product flavors when you have to use more complicated directory structures: