All Products
Search
Document Center

Mobile Platform as a Service:Switch workspace

Last Updated:Dec 01, 2023

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.

When performing static workspace switching, easyconfig is used. easyconfig working principle:

  • Modify meta properties related to AndroidManifest workspace.

  • Modify the mpaas.properties file under assets.

  • 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.

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.

     classpath 'com.alipay.android:android-gradle-plugin:3.0.0.9.13'
     // Set a version number that is no earlier than 2.8.0.
     classpath 'com.android.boost.easyconfig:easyconfig:2.8.0'
  2. Ensure that the following configuration (sequence to be observed) exists in build.gradle of the main project (android main module).

     apply plugin: 'com.alipay.portal'
     // Append it to com.alipay.portal
     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). See the figure below.

    Important

    Keep only the configuration file of the corresponding workspace.

    修改11.png

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.

     classpath 'com.alipay.android:android-gradle-plugin:3.0.0.9.13'
     // Set a version number that is no earlier than 2.8.0.
     classpath 'com.android.boost.easyconfig:easyconfig:2.8.0'
  2. Ensure that the following configuration (the order must be followed) exists in build.gradle of the main project (android main module).

    apply plugin: 'com.alipay.portal'
     // Append it to com.alipay.portal
     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). See the figure below.

    image.png

    Important

    Keep only the configuration file of the corresponding workspace.

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

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.

Note
  • 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.

    p427361

Add a dynamic workspace switching SDK

  1. Add dependencies.

    • AAR access methods

      Under the dependencies node in the build.gradle file of the main module, add the following dependencies:

      dependencies {
      ···
      implementation 'com.mpaas.mocksettings:mocksettings-build:10.1.60a.1575@aar'
      ···
      }
    • Portal&Bundle method

      Under the dependencies node in the build.gradle file of the main module of the portal project, add the following dependencies:

      dependencies {
       ···
       bundle 'com.mpaas.mocksettings:mocksettings-build:1.0.0.200421111458@jar'
       manifest 'com.mpaas.mocksettings:mocksettings-build:1.0.0.200421111458:AndroidManifest@xml'
       ····
      }
  2. Use SDK.

    • If using AAR access methods, rewrite the getPackageManager of Application, and replace PackageManager with MockSettingsPackageManager.

      private MockSettingsPackageManager mockSettingsPackageManager;
      
      @Override
      public PackageManager getPackageManager() {
          if (mockSettingsPackageManager == null) {
              mockSettingsPackageManager = new MockSettingsPackageManager(this, super.getPackageManager());
          }
          return mockSettingsPackageManager;
      }
    • If using Portal&Bundle method, modify the application of AndroidManifest.xml under the main module of Portal project.

      <application
           android:name="com.alipay.mobile.quinox.MockSettingsLauncherApplication"
           ···
           >
           ···
      </application>
  3. Add the following permission and make sure it has been dynamically requested during runtime.

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  4. Compile the debug package or turn on debug settings in AndroidManifest.xml.

    <application
         android:debuggable="true"
         ···
         >
         ···
    </application>

Dynamic switching

  1. Scan the QR code to download the mPaaS setup App.p349172 After installation, the icon of the mPaaS setup App is displayed as follows:

    app

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

  3. 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.

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

  4. Switch to another workspace.

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

  6. 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.