How to switch config files for multi-environment packages in mPaaS

更新时间:
复制 MD 格式

mPaaS supports switching between multiple development environments, such as DEV, TEST, UAT, and PROD.

Download the config files

  1. Go to the mPaaS console and create a workspace for each required environment.

  2. Upload the signed APK to each workspace. Ensure that the package name and signature match your project. Then, download the corresponding config file.

Add the config files to the project

In the src directory of your app module, create a folder for each environment and place the corresponding config file in it.

Upgrade the easyconfig plugin

Upgrade the easyconfig plugin to version 2.8.0.

 classpath 'com.android.boost.easyconfig:easyconfig:2.8.0'

Configure Gradle

In the build.gradle file of the app module, add the following configuration to the android node:

 flavorDimensions "version"
    productFlavors {
        flavorDev {
            dimension "version"
            applicationIdSuffix ".flavorDev"
        }

        flavorProd {
            dimension "version"
            applicationIdSuffix ".flavorProd"
        }
    }

The flavor name (for example, flavorDev) must match the folder name you created in the src directory. You can use any custom name.

Switch environments in Android Studio

In Android Studio, click the drop-down list next to flavorDevDebug to switch to the desired environment.

Verify that the configuration is effective

Drag the package built for each environment into Android Studio and open its AndroidManifest.xml file. If the manifest values match those in the config file, the configuration is applied successfully.