firebase-remote-config-basics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Remote Config

Remote Config

This skill provides a complete guide for getting started with Remote Config on Android or iOS. Remote Config allows you to change the behavior and appearance of your app without publishing an app update by maintaining a cloud-based configuration template.
本技能提供了在Android或iOS上开始使用Remote Config的完整指南。Remote Config允许您通过维护基于云的配置模板,无需发布应用更新即可更改应用的行为和外观。

Prerequisites

前提条件

Provisioning Remote Config requires both a Firebase project and a Firebase app, either Android or iOS. To manage the Remote Config template and conditions via the command line, use the Firebase CLI. See the
firebase-basics
skill for references on project initialization.
配置Remote Config需要一个Firebase项目以及一个Firebase应用(Android或iOS均可)。要通过命令行管理Remote Config模板和条件,请使用Firebase CLI。有关项目初始化的参考,请查看
firebase-basics
技能。

Troubleshooting Execution

执行故障排除

Handling npx 403 Forbidden Errors

处理npx 403禁止错误

If
npx -y firebase-tools@latest
fails due to registry permissions (403 error):
  1. Inform the user: "I am unable to fetch the latest Firebase tools via npx due to a registry error."
  2. Fallback: Attempt to use the local
    firebase
    command directly if the user confirms it is installed globally (
    npm install -g firebase-tools
    ).
如果
npx -y firebase-tools@latest
因注册表权限问题(403错误)失败:
  1. 告知用户:“由于注册表错误,我无法通过npx获取最新的Firebase工具。”
  2. 备选方案:如果用户确认已全局安装Firebase工具(
    npm install -g firebase-tools
    ),尝试直接使用本地
    firebase
    命令。

Handling Project Context Issues

处理项目上下文问题

If a command fails because "no active project is selected":
  1. Check login: Run
    npx -y firebase-tools@latest login:list
    .
  2. Prompt for ID: If logged in but no project is active, ask the user: "Please provide your Firebase Project ID to proceed."
  3. Use Flag: Append
    --project <PROJECT_ID>
    to every subsequent command.
如果命令因“未选择活动项目”而失败:
  1. 检查登录状态:运行
    npx -y firebase-tools@latest login:list
  2. 请求项目ID:如果已登录但未选择活动项目,请询问用户:“请提供您的Firebase项目ID以继续。”
  3. 使用项目标志:在后续所有命令后添加
    --project <PROJECT_ID>

SDK Setup

SDK设置

To learn how to set up Remote Config in your application code, choose your platform:
  • Android: android_setup.md
  • iOS: ios_setup.md
要了解如何在应用代码中设置Remote Config,请选择您的平台:
  • Androidandroid_setup.md
  • iOSios_setup.md

Best Practices and Template Management

最佳实践与模板管理

Follow these guidelines and use the associated CLI tools to ensure efficient and safe use of Remote Config.
遵循以下指南并使用相关CLI工具,确保高效、安全地使用Remote Config。

Fetching Strategies

获取策略

To optimize app performance and user experience, follow these recommended patterns (see Loading Strategies):
  • Load new values for next startup: The most effective pattern is to activate previously fetched values immediately on startup and fetch new values in the background to be used next time. This minimizes user wait time.
  • Real-time Updates: Use the SDK's real-time listener to update the app instantly without a refresh when server-side configuration changes.
为优化应用性能和用户体验,请遵循以下推荐模式(参见加载策略):
  • 为下次启动加载新值:最有效的模式是在启动时立即激活之前获取的值,并在后台获取新值以便下次使用。这能最大限度减少用户等待时间。
  • 实时更新:使用SDK的实时监听器,当服务器端配置更改时,无需刷新即可立即更新应用。

Template Management via CLI

通过CLI管理模板

Use the following commands to manage your Remote Config template and version history through the terminal:
使用以下命令通过终端管理您的Remote Config模板和版本历史:
  • 获取当前模板:将远程模板保存到本地JSON文件,以便审核或修改。
    bash
    npx -y firebase-tools@latest remoteconfig:get -o remote_config.json
  • 自主编辑与探索:直接修改本地
    remote_config.json
    文件。确定正确的信号(例如device.country或percent)并相应更新“conditions”数组和“parameters”映射。
  • 强制要求:用户审核与验证:停止操作并请用户在部署前验证您的更改。
    • 操作:告知用户:“我已在remote_config.json中准备好更改。请检查文件是否准确。确认无误后,请告诉我‘部署’以启用更改。”
  • 部署编排:要推送更改,必须确保环境已配置为可部署状态。
    • 配置映射:如果缺少firebase.json文件,请创建一个以将本地JSON映射到Remote Config服务:
    json
      { "remoteconfig": { "template": "remote_config.json" } }
    • 部署:执行部分部署命令
      bash
      npx -y firebase-tools@latest deploy --only remoteconfig
  • 验证:部署后,通过列出版本历史来验证更新。
    bash
    npx -y firebase-tools@latest remoteconfig:versions:list
SDK提供了多项功能,让您的应用能够根据用户群体动态响应。
  • 设置应用内默认值:定义基准值,确保应用在离线状态或首次获取前能正常运行。
  • 获取并激活:从Firebase后端检索值并将其应用到本地UI/逻辑。
  • 模板管理:使用Firebase CLI对配置JSON文件进行版本控制、获取和部署。

Template Management via CLI

Use the following commands to manage your Remote Config template and version history through the terminal:
  • Get current template: Save the remote template to a local JSON file for auditing or modification.
    bash
    npx -y firebase-tools@latest remoteconfig:get -o remote_config.json
  • Autonomous Editing & Discovery : Modify the local
    remote_config.json
    directly. Determine the correct signal (e.g., device.country or percent) and update the "conditions" array and "parameters" map accordingly.
  • MANDATORY: User Review and Verification : STOP and ask the user to verify your changes before proceeding to deployment.
    • Action: Inform the user: "I have prepared the changes in remote_config.json. Please review the file for accuracy. Once you are satisfied, tell me to 'deploy' to make the changes live."
  • Deployment Orchestration : To push changes, you must ensure the environment is configured for deployment.
    • Config Mapping: If a firebase.json file is missing, create one to map the local JSON to the Remote Config service:
    json
      { "remoteconfig": { "template": "remote_config.json" } }
    • Deploy: Execute the partial deployment command
      bash
      npx -y firebase-tools@latest deploy --only remoteconfig
  • Verification: After deployment, verify the update by listing the version history.
    bash
    npx -y firebase-tools@latest remoteconfig:versions:list
The SDK provides a number of features to make your application dynamic and responsive to user segments.
  • Set In-App Defaults: Define baseline values to ensure the app functions offline or before the first fetch.
  • Fetch and Activate: Retrieve values from the Firebase backend and apply them to the local UI/Logic.
  • Template Management: Use the Firebase CLI to version-control, get, and deploy your config JSON files.