android - What does google-services.json really do? -


i work on adding google analytics , gcm services current app. on guide both services implementation, google asks developer generate json file: google-services.json , put under root directory of app.

i found if delete json file app, services still works.

just want know sure, file for? usage , how work?

i investigated bit regarding google-services plugin , json , found sources plugin.

first things first

the gradle-plugin google-services referenced classpath , apply build-time plugin only! influences build-process of app, not runtime-process!

this plugin meant quickstart-helper integrating google-services in app. obviously, process convoluted , not documented, google should have made clear process does.

in fact, found source code plugin version com.google.gms:google-services:1.4.0-beta3 , didnt find specific reference in regarding appinvites nor did find google api app invites! (but maybe uses generic api project project id, didnt try this)

what does

the google-services gradle-plugin looks mentioned google-services.json file in app-module. looks configured settings project-id's , tracking-id's , such, generated google api developer console google-services.json file. settings found, android resource values generated following path:

$project.builddir/generated/res/google-services/$variant.dirname/values/values.xml 

for example debug-build of app:

app/build/generated/res/google-services/debug/values/values.xml 

e.g. if followed gcm tutorial, json file include api project's id following android-resource:

<string name="gcm_defaultsenderid">project-id</string> 

so plugin , json file not essential running or publishing app, quickstart helper generate basic android-resource files easier integration of specific google api features.

notice in source code referenced below google-services plugin generates android-resources every app-variant defined in app/build.gradle.

if don't want that, should use generated resources in app-variants want, , delete others. don't forget remove google-services plugin apply app/build.gradle, or else regenerated app-variants.

what not

this plugin , json-file not directly influence inner workings of said google-features app! if have followed older tutorials on developer.android.com on how integrate e.g. gcm or google analytics, don't need integrate either gradle-plugin google-services or google-services.json file!

notice found sources

after integrated google-services gradle-plugin , when sync project, gradle automatically downloads google-services dependency path similar (on windows, might need home/.gradle linux):

c:\users\user\.gradle\caches\modules-2\files-2.1\com.google.gms\google-services\1.4.0-beta3\f1580f62e3be313eba041ce19b64fd3f44cf8951\google-services-1.4.0-beta3-sources.jar 

if extract jar-file, find 2 files:

googleservicesplugin.groovy googleservicestask.java 

which contain plain source code of gradle-plugin.

googleservicesplugin.groovy 

contains handling of app-variants , basic definitions of paths etc.

googleservicestask.java 

contains actual task-definition, following method see does:

@taskaction public void action() throws ioexception {  

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -