All Products
Search
Document Center

Mobile Platform as a Service:How to switch between multiple development environments in an mPaaS Android project

Last Updated:Feb 04, 2026

The mPaaS Android 60 baseline lets you switch between multiple development environments, such as development (DEV), testing (TEST), user acceptance testing (UAT), and production (PROD).

mPaaS-related changes

For mPaaS developers, switching development environments involves changing the following configuration files:

  • mPaaS project configuration: Configure the.config file Ant-mpaas-xxx-Android.config in the project under the app directory of the portal. This file can be used to store service address and gateway service address for application pushing service. For details, see Create mPaaS application in the console.

  • RPC data encryption configuration : Configure the mpaas_netconfig.properties file in the project under the assets directory of the portal. This file can be used to store RPC data encryption methods and public encryption keys. For details, see Data Encryption > Android Configuration.

  • HTML5 container configuration: Configure the custom_config.json file in the project under the assets directory of the portal. This file can be used to store the switches of offline package signature verification and immersive title bar. For details, see HTML5 container configuration.

  • Public key for offline package signature verification: The public key is used to decrypt the offline package in the project. The public key is configured in the code and can be set through the Nebula component. For details, see Configure offline package.

When you switch development environments, you must manually replace or modify these configurations in your project. The next section explains how to use Gradle configurations to simplify switching between environments.

Solutions

There are two types of configurations to modify when switching development environments:

  • Configuration files: These include the mPaaS project configuration, RPC data encryption configuration, and H5 container configuration files. You can replace these files during compilation using a Gradle script.

  • Code configurations: These include settings such as the offline package signature verification public key. You can add these settings to a configuration file and then switch them by reading that file.

Preparations

  • Under portal-app, create various development environment directories to store configuration files according to project requirements.

  • Copy the mPaaS project configuration for each environment to its corresponding folder.

  • To switch the RPC data encryption configuration, copy `mpaas_netconfig.properties` to the corresponding folder.

  • To switch the H5 container configuration, copy `custom_config.json` to the corresponding folder.

Switch configuration files

Switch the mPaaS project configuration

Configure the following code in the gradle of portal-app :

// Configure the mPaaS App development environment. Copy the .config file to the main module.
def setAppConfigEnv(String type){
    File configFile = file("${rootDir}/app").listFiles().find{File f ->
        f.name.endsWith(".config")
    }
    if(configFile != null && configFile.exists()){
        delete(configFile)
    }

    copy {
        from "buildEnv/${type}"
        into "${rootDir}/app"
        include "**/*.config"
    }
}

Switch the RPC data encryption configuration

Configure the following code in the gradle of portal-app :

// Configure the RPC data encryption development environment. Copy the configuration file to the assets resource folder.
def setNetConfigEnv(String type){
    copy {
        from "buildEnv/${type}/mpaas_netconfig.properties"
        into "${rootDir}/app/src/main/assets"
    }
}

Switch the H5 container configuration

Configure the following code in the gradle of portal-app :

// Configure the offline package development environment. Copy the configuration file to the assets resource folder.
def setNebulaEnv(String type){
    copy {
        from "buildEnv/${type}/custom_config.json"
        into "${rootDir}/app/src/main/assets/config"
    }
}

Switch code configurations

Switch the offline package signature verification public key

  1. Add the offline package signature verification key to the custom_config.json file:

    [
    {
     "value": "YES",
     "key": "h5_shouldverifyapp"
    },
    {
     "value": "your public key",
     "key": "h5_shouldverifyapp_pubkey"
    }
    ]
  2. Read the H5 container configuration to retrieve the offline package signature verification public key. You can then switch the public key by switching the H5 container configuration file:

         /**
          * Parses the offline package signature verification public key from the H5 container configuration file.
          * @return The offline package signature verification public key.
          */
         public String getAppVerificationPubkey(){
             String configStr = getFromAssets("config/custom_config.json");
             JSONArray jsonArray = JSON.parseArray(configStr);
             if(jsonArray != null && jsonArray.size() > 0){
                 for (int i = 0; i < jsonArray.size(); i++) {
                     JSONObject jsonObject = jsonArray.getJSONObject(i);
                     String key = jsonObject.getString("key");
                     if(key.equals("h5_shouldverifyapp_pubkey")){
                         String value = jsonObject.getString("value");
                         return value;
                     }
                 }
             }
             return null;
         }
    
         /**
          * Gets the content of a file in the portal assets folder.
          * @param fileName The file name.
          * @return The file content.
          */
         public String getFromAssets(String fileName){
             try {
                 MicroApplicationContext context = MPFramework.getMicroApplicationContext();
                 InputStreamReader inputReader = new InputStreamReader(context.getApplicationContext().getResources().getAssets().open(fileName));
                 BufferedReader bufReader = new BufferedReader(inputReader);
                 String line= "";
                 String Result= "";
                 while((line = bufReader.readLine()) != null)
                     Result += line;
                 return Result;
             } catch (Exception e) {
                 e.printStackTrace();
             }
             return null;
         }
  3. Set the offline package signature verification public key:

     String pubkey = getAppVerificationPubkey();
     if(!TextUtils.isEmpty(pubkey)){
         MPNebula.enableAppVerification(pubkey);
     }

Switch the development environment

Configure in the gradle of portal-app. After you call this method and pass in environment parameters, automatic switching can be implemented:

// Switch the development environment based on the environment type.
// type can be dev, test, uat, or prod. You can extend this based on your configuration folders.
def switchBuildEnv(String type){
    setAppConfigEnv(type)
    if(file("buildEnv/${type}/custom_config.json").exists()){
        setNebulaEnv(type)
    }
    if(file("buildEnv/${type}/mpaas_netconfig.properties").exists()){
        setNetConfigEnv(type)
    }
}

Code sample

Call the switch method in the gradle of portal-app:

buildTypes {
     // Switch the development environment.
    switchBuildEnv('prod')
    release {
        ...
    }
    debug {
        ...
    }
}

You can click here to download the code sample.