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 toAndroidManifest workspace
.Modify the
mpaas.properties
file underassets
.If the configuration file of the
mPaaS
project contains thebase64
property which is not null, a Security Guard encrypted pictureyw_1222.jpg
is generated.
Public cloud
In a public cloud, perform the following steps to switch the workspace:
Ensure that the following dependency exists in the
build.gradle
file under the root directory of the project:NoteThe 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'
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'
Download the
.config
configuration file of the corresponding workspace from the console. For more information, see Create Application in Console > Download Configuration File.Add the downloaded
.config
configuration file to the path of the main project (android main module
). See the figure below.ImportantKeep only the configuration file of the corresponding workspace.
Apsara Stack
In a private cloud, perform the following steps to switch the workspace:
Ensure that the following dependency exists in the
build.gradle
file under the root directory of the project.NoteThe 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'
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'
Download the
.config
configuration file of the corresponding workspace from the console. For more information, see Create an application in console > Download configuration files.Add the downloaded
.config
configuration file to the path of the main project (android main module
). See the figure below.ImportantKeep only the configuration file of the corresponding workspace.
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.
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
Add dependencies.
AAR access methods
Under the
dependencies
node in thebuild.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 thebuild.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' ···· }
Use SDK.
If using AAR access methods, rewrite the
getPackageManager
of Application, and replacePackageManager
withMockSettingsPackageManager
.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
ofAndroidManifest.xml
under the main module of Portal project.<application android:name="com.alipay.mobile.quinox.MockSettingsLauncherApplication" ··· > ··· </application>
Add the following permission and make sure it has been dynamically requested during runtime.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Compile the debug package or turn on debug settings in
AndroidManifest.xml
.<application android:debuggable="true" ··· > ··· </application>
Dynamic switching
Scan the QR code to download the mPaaS setup App. After installation, the icon of the mPaaS setup App is displayed as follows:
Place the
config
file downloaded from the mPaaS console in the SD card of the mobile phone.Add a workspace. Add the
config
file to the list by using the mPaaS setup App.Open the mPaaS setup App.
Click Add configuration file at the bottom of the Workspace list page.
Find the workspace configuration files to be added.
Add the two files (formal workspace and test workspace) to the workspace list.
Switch to another workspace.
Select a workspace in the preceding figure and click Switch to switch to the selected workspace.
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.