All Products
Search
Document Center

Switch workspace

Last Updated: Apr 01, 2021

During app development, the app environment (namely, workspace) may occasionally change, and the app may be developed in multiple workspaces in parallel. mPaaS provides a tool for you to conveniently switch among workspaces during development. There are two types of workspace switching modes:

Static workspace switching

Prerequisites

You have an app developed based on the mPaaS framework. For more information, see mPaaS Based Framework > Quick Start.

Public cloud

In a public cloud, perform the following steps to switch the workspace:

  1. Ensure that the following dependency exists in the build.gradle file under the root directory of the project:

    Note: The following dependency version number may increase constantly due to function iterations.
    1. classpath 'com.alipay.android:android-gradle-plugin:3.0.0.9.13'
    2. // Set a version number that is no earlier than 2.1.0.
    3. classpath 'com.android.boost.easyconfig:easyconfig:2.4.8'
  2. Ensure that the following configuration (sequence to be observed) exists in build.gradle of the main project (android main module).
    1. apply plugin: 'com.alipay.portal'
    2. // Append it to com.alipay.portal
    3. apply plugin: 'com.alipay.apollo.baseline.update'
  3. Download the .config configuration file of the corresponding workspace from the console. For more information, see Create Application in Console > Download Configuration File.
  4. Add the downloaded .config configuration file to the path of the main project (android main module). Note: Keep only the configuration file of the corresponding workspace. See the figure below.

Apsara Stack

In a private cloud, perform the following steps to switch the workspace:

  1. Ensure that the following dependency exists in the build.gradle file under the root directory of the project:

    Note: The following dependency version number may increase constantly due to function iterations.
    1. classpath 'com.alipay.android:android-gradle-plugin:3.0.0.9.13'
    2. // Set a version number that is no earlier than 2.1.0.
    3. classpath 'com.android.boost.easyconfig:easyconfig:2.4.8'
  2. Ensure that the following configuration (the order must be followed) exists in build.gradle of the main project (android main module).
    1. apply plugin: 'com.alipay.portal'
    2. // Append it to com.alipay.portal
    3. apply plugin: 'com.alipay.apollo.baseline.update'
  3. Download the .config configuration file of the corresponding workspace from the console. For more information, see Create an application in console > Download configuration files.
  4. Add the downloaded .config configuration file to the path of the main project (android main module). Note: Keep only the configuration file of the corresponding workspace. See the figure below.

  5. Use the mPaaS plug-in to generate an encrypted image yw_1222.jpg. For more information, see Generate an encrypted image (Apsara Stack).

Notes

easyconfig working principle:

  1. Modify meta properties related to AndroidManifest workspace.
  2. Modify the mpaas.properties file under assets.
  3. If the configuration file of the mPaaS project contains the base64 property which is not null, a Security Guard encrypted picture yw_1222.jpg is generated.

Dynamic workspace switching

In dynamic workspace switching, workspace options in mobile phone settings are modified to dynamically modify the app workspace information without repackaging on the client.

Notes:
  • The function of static workspace switching is available in the Apsara Stack environment only.
  • Dynamic workspace switching applies to a scenario where multiple sets of workspaces exist and are switched frequently in the development phase.
  • The environment profile of the new environment must be written to the application when dynamic environment switching is applied. Therefore, you need to request file storage permissions for the application when using this approach.

Restricted by the mPaaS security signature verification mechanism, updating workspace configuration information will modify the Security Guard signature verification picture yw_1222.jpg. Therefore, dynamic workspace switching has two restrictions.

  • Applicable only to the development phase: Dynamic workspace switching applies only to the development phase. Delete the corresponding configuration before getting online (the release package reports a RuntimeException exception).

  • Signature verification for network requests must be disabled in the mPaaS console. Otherwise, requests will fail due to incorrect signature verification image information.

Add a dynamic workspace switching SDK

  1. Under the dependencies node in the build.gradle file of the main module of the portal project, add the following dependencies:
    1. dependencies {
    2. ···
    3. bundle 'com.mpaas.mocksettings:mocksettings-build:1.0.0.200421111458@jar'
    4. manifest 'com.mpaas.mocksettings:mocksettings-build:1.0.0.200421111458:AndroidManifest@xml'
    5. ····
    6. }
  2. Under the application node in the AndroidManifest.xml file of the main module of the portal project, modify the configuration as follows:

    1. <application
    2. android:name="com.alipay.mobile.quinox.MockSettingsLauncherApplication"
    3. android:debuggable="true"
    4. ···
    5. >
    6. ···
    7. </application>

    Dynamic switching

  3. Scan the QR code to download the mPaaS setup app.

    After installation, the icon of the mPaaS setup app is displayed as follows:

    app

  4. Place the config file downloaded from the mPaaS console in the SD card of the mobile phone.

  5. Add a workspace. Add the config file to the list by using the mPaaS setup app.

    1. Open the mPaaS setup app.
    2. Click Add configuration file at the bottom of the Workspace list page.

      1. Find the workspace configuration files to be added.

      1. Add the two files (formal workspace and test workspace) to the workspace list.

  6. Switch to another workspace.

    1. Select a workspace in the preceding figure and click Switch to switch to the selected workspace.

    2. Then start the app corresponding to the workspace. If a test request can be properly sent, switching to the target workspace succeeds.

    If you switch to another workspace and restart the app corresponding to the earlier workspace, the system reports a 3000 exception because the new workspace does not contain the corresponding operationType. This is normal after you successfully switch to another workspace.