简体   繁体   English

如何在多个包 ID(同一项目)Android 中使用 Firebase 远程配置

[英]How to use Firebase Remote Config in multiple package id (same project) Android

I have used Flavour in Android studio for deploy different version(Demo,Production) in one device, but I also use firebase remote config where I registered it to one package id.我在 Android Studio 中使用 Flavor 在一台设备上部署不同的版本(Demo,Production),但我也使用 firebase 远程配置,我将它注册到一个包 ID。 is it possible to make firebase remote config works in multiple package id?, I want to use it in my Demo and Production app.是否可以让 firebase 远程配置在多个包 ID 中工作?,我想在我的演示和生产应用程序中使用它。

The documented advice for working with multiple environments , such as development and production, is to have one project for each environment.使用多种环境(例如开发和生产)的文档建议是每个环境都有一个项目。 Your app will typically have a unique application ID for each environment, which lets it read remote config parameters for the project that it will access, which is easy to configure with Android build variants .对于每个环境,您的应用程序通常都有一个唯一的应用程序 ID ,这让它可以读取将要访问的项目的远程配置参数,这很容易使用Android 构建变体进行配置。

Here is my answer这是我的答案

Remote config can be setup for below conditions可以为以下条件设置远程配置

  • Only for different projects : ex : amazon, flipkart仅适用于不同的项目:例如:amazon、flipkart
  • Same project with different productFlavors ex : amazonPay, amazonShopping不同的同一项目productFlavors例如:amazonPay,amazonShopping
  • Same project with different buildTypes ex : amazon.dev, amazon.prod, amazon.experiment具有不同buildTypes相同项目,例如:amazon.dev、amazon.prod、amazon.experiment

Here is sample code to setup remoteConfig, it might help you/others Make sure you setupRemoteConfig in onCreate of Application.java file这是设置 remoteConfig 的示例代码,它可能会帮助您/其他人确保您在Application.java文件的onCreate中设置了 setupRemoteConfig

private void setupRemoteConfig() {
    final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
    remoteConfig.setDefaults(R.xml.remote_config_default);
    remoteConfig.fetch(300).addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            remoteConfig.activateFetched();
        }
    });
}

You can add multiple application package names under project settings so that they all can use common firebase services.您可以在项目设置下添加多个应用程序包名称,以便它们都可以使用常见的 Firebase 服务。 In this way, you can share single project resources among multiple applications.通过这种方式,您可以在多个应用程序之间共享单个项目资源。

You can create service accounts for every environment and you can use that, if its a database you can create two separate nodes for Production and Development .您可以为每个环境创建服务帐户,并且可以使用它,如果它是一个数据库,您可以为ProductionDevelopment创建两个单独的节点。

Thank You for reading感谢您的阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 远程配置 - android - Firebase Remote Config - android Firebase 远程配置:如何更改值参数 - Firebase Remote Config: How to Change Value Parameters 如何在Android中将多个身份验证提供程序与Firebase一起使用 - How to use Multiple Authentication Providers with Firebase In Android 如何将同一个程序包的多个版本作为项目的间接依赖项? - How to have multiple versions of the same package as the indirect dependencies of a project? Firebase 远程配置:如何在 Map 中获取所有配置<string, string></string,> - Firebase Remote Config: How to get all config in Map<String, String> 如何在 Android Studio 的同一个项目中同时使用两个模拟器? - How to use two emulators at the same time in the same project in Android Studio? 在Android项目中使用Gradle覆盖具有相同包的类 - Override classes with same package with Gradle in an Android project 如何在单个 Android 应用程序中同时使用两个 firebase 项目? - How to use two firebase projects in single Android app at same time? Firebase-远程配置应用程序更新 - Firebase - Remote Config App Update 如何在多个 api 调用中使用相同的跟踪 ID - How to use the same trace id in multiple api calls
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM