首页 > 解决方案 > 在将 Android 应用程序集成到 Firebase 远程配置时,如何使用 2 个 google-services.json(一个用于 PROODUCTION,另一个用于 QA 环境)?

问题描述

如果我在 SRC 下创建 2 个子文件夹(例如 QA 和 PROD 并放置 google-services.json 文件),这就足够了吗?应用程序将如何理解为应用程序的 qa/生产版本选择哪个文件。

标签: androidfirebase

解决方案


看看使用应用程序风味。

|--> app
|----> src
|------> main (this is where you 'base' product build goes
|--------> google-services.json (google services for main - Default)
|--------> res (res files for main - Default)

|------> qa (this is named the same as one of your flavours)
|--------> google-services.json (google services for qa)
|--------> res (res files for qa)
|----------> drawable-xxxhdpi (drawables for qa)
|----------> values (values files for qa, e.g. strings.xml)

|------> prod (this is named the same as one of your flavours)
|--------> google-services.json (google services for prod)
|--------> res (res files for prod)
|----------> drawable-xxxhdpi (drawables for prod)
|----------> values (values files for prod, e.g. strings.xml)

应用程序构建.gradle

...

flavorDimensions "main"
productFlavors {
    qa {
        applicationId = "com.your.appl.qa";
        versionNameSuffix "_QA"
    }
    prod {
        applicationId = "com.your.appl";
        versionNameSuffix "_PROD"
    }
}
...

然后,您可以在 Build Variants 窗口中切换风格:

构建变体菜单


推荐阅读