【问题标题】:Switch GCM Client on Development and Production在开发和生产上切换 GCM 客户端
【发布时间】:2015-09-25 19:27:13
【问题描述】:

只需实施新的 GCM。官方文档,

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

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

【问题讨论】:

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


【解决方案1】:

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

在您的情况下,它是调试/生产。我不知道您为什么需要在生产和调试之间切换,但我认为您可以按照我为风味提出的建议做同样的事情。

创建两个额外的文件夹 src/releasesrc/debug ,在每个文件夹中放置相应的 google-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
}

【讨论】:

    【解决方案2】:

    根据我的测试切换构建类型或风格,我注意到我们应该将它们区分如下:

    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.
    

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-01
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多