New Dynamic Environment Switching

更新时间:
复制 MD 格式

Dynamic environment switching lets you change the runtime environment of a debug build — switching between development, testing, and production configurations — without rebuilding the app. This feature requires mPaaS main integration baseline version 10.2.3.77 or later.

Prerequisites

Before you begin, make sure you have:

  • mPaaS main integration baseline version 10.2.3.77 or later

Add the dependency

implementation "com.mpaas.mocksettings:mocksettings-build:1.0.0.260514112908@aar"

Configure dynamic environment switching

  1. Set up multi-environment configuration files.

    Place the configuration files for each environment in the assets/debug_env directory, as shown in the following image.

    Note

    If you skip this step, the system reads the configuration file from the main module by default.

    image.png

  2. Specify the runtime configuration file.

    MockSettingsUtil.configName = "mpaas-debug.config"
  3. Configure Blue Shield images for multiple environments.

    Store your Blue Shield images in the assets directory, each with a unique filename. Call the following API at runtime to specify which image to load.

    image.png

    MPBS.setBSAuthCodeDynamically(String bsAuthCode)

    API parameters

    • Parameter description: bsAuthCode must be the image filename without the file extension. For example, if the filename is test.jpg, pass test.

    • Default value: If you do not call this API, the default image filename is abs_1222.

    • Constraint: bsAuthCode cannot be an empty string.

    • Multi-image handling: Generated images default to the name abs_1222. To use separate images for different environments, rename each generated image before generating the next one to prevent files from being overwritten.