在开发和生产中切换GCM客户端

时间:2015-07-08 04:01:11

标签: android push-notification google-cloud-messaging push

只需实施新的GCM。对于官方文件,

  

将刚刚下载的google-services.json文件复制到Android Studio项目的app /或mobile /目录中。

任何人都知道如何设置gradle来切换开发和生产以使用不同的google-services.json?

2 个答案:

答案 0 :(得分:2)

我刚刚针对不同的productFlavors回答了类似问题here

在你的情况下它是调试/生产。我不知道为什么你需要在生产和调试之间切换,但我认为你可以像我提出的口味一样做。

在您放置相应src/release的每个文件夹中创建两个额外的文件夹src/debuggoogle-services.json,这样您就可以:src/release/google-services.jsonsrc/debug/google-services.json

现在在gradle中添加:

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
}

答案 1 :(得分:0)

根据我的测试切换版本类型或风格,我注意到我们应该对它们进行如下区分:

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.