问题
Just implement the new GCM. For official document,
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.
Anyone know how to setup gradle to switch development and production to use different google-services.json?
回答1:
I have just answered a similar question here for different productFlavors
.
In your case it's debug/production. I don't know why you need to switch between production and debug but i think you can do the same as what I proposed for flavors.
Create two extra folders src/release
and src/debug
, in each of the folders you put the corresponding google-services.json
, so you will have: src/release/google-services.json
and src/debug/google-services.json
Now in gradle add this :
android {
// set build config here to get the right gcm configuration.
//def myBuildConfig = "release"
def myBuildConfig = "debug"
// this will copy the right google-services.json file to app/ directory.
if (myBuildConfig.equals("release")) {
println "--> release copy!"
copy {
from 'src/release/'
include '*.json'
into '.'
}
} else {
println "--> debug copy!"
copy {
from 'src/debug/'
include '*.json'
into '.'
}
}
// other stuff
}
回答2:
Base on my test switching build type or flavor, I noted that we should differentiate them as following:
For Debugging:
src/flavorDebug/google-services.json
src/flavor/debug/google-services.json
src/debug/flavor/google-services.json
If all flavors use only one firebase project with different app ids:
src/debug/google-services.json
For Releasing:
src/flavorRelease/google-services.json
src/flavor/release/google-services.json
src/release/flavor/google-services.json
If all flavors use only one firebase project with different app ids:
src/release/google-services.json
Without flavor should be as the following:
src/debug/google-services.json
src/release/google-services.json
With flavor but not separate build type:
src/flavor/google-services.json
For overall flavors and build types:
src/google-services.json
Note: flavor is referred to your flavor's name.
来源:https://stackoverflow.com/questions/31283299/switch-gcm-client-on-development-and-production