The new Mini Program container is available only in baseline 10.2.3. It supports only the native AAR connection type. For more information, see Introduction to the native AAR connection type.
Prerequisites
Before you connect the new Mini Program container to Android, you must activate mPaaS and complete the connection process using the native AAR connection type. For more information, see Add mPaaS to your project.
Procedure
The procedure for integrating a new Mini Program container is as follows:
The following sections describe each step in detail.
Select a baseline
Add baseline 10.2.3.
Click mPaaS > Native AAR Connection. In the panel that appears, click Start Configuration under Add/Upgrade Baseline to add baseline 10.2.3.
Add the Mini Program component.
In your project, install the Mriver Tiny App component using Component Management (AAR).
Initialize configurations
Initialize mPaaS
Initialize through the mPaaS framework (recommended)
Add the initialization code to the
Applicationclass.public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); // Initialize mPaaS MP.init(this); } }For more information, see Initialize mPaaS.
Add the meta configuration to
AndroidManifest.xml.<meta-data android:name="mpaas.init.param" android:value="com.xxx.xxx.MriverInitImpl" />Add
com.xxx.xxx.MriverInitImpland implementMPInitParamManifest.import android.content.Context; import com.mpaas.core.MPInitParam; import com.mpaas.mriver.api.init.MriverInitParam; public class MriverInitImpl implements com.mpaas.MPInitParamManifest { @Override public MPInitParam initParam(Context context) { MriverInitParam mriverInitParam = MriverInitParam.getDefault(); mriverInitParam.setMriverInitCallback(new MriverInitParam.MriverInitCallback() { @Override public void onInit() { if (com.alibaba.ariver.kernel.common.utils.ProcessUtils.isMainProcess()) { // Mini Program-related configurations, such as custom JSAPIs and title bars } } @Override public void onError(Exception e) { } }); return MPInitParam.obtain().addComponentInitParam(mriverInitParam); } }
Initialize mPaaS using MPInit
To initialize mPaaS, add the following code to the Application class.
public class MyApplication extends Application implements MPInitParam.MPCallback {
@Override
public void onCreate() {
super.onCreate();
// Initialize mPaaS
MriverInitParam mriverInitParam = MriverInitParam.getDefault();
mriverInitParam.setMriverInitCallback(new MriverInitCallback() {
@Override
public void onInit() {
if (com.alibaba.ariver.kernel.common.utils.ProcessUtils.isMainProcess()) {
// Mini Program-related configurations, such as custom JSAPIs and title bars
}
}
@Override
public void onError(Exception e) {
}
});
MP.init(this, MPInitParam.obtain().setCallback(this).addComponentInitParam(mriverInitParam));
}
@Override
public void onInit() {
// init success
}
}Mini Program signature verification configuration
The Mini Program container provides a package signature verification feature. By default, this feature is disabled for debug packages and enabled for release packages. You can control this feature using an API.
// Disable signature verification
MriverResource.disableVerify();
// Enable signature verification. xx is the public key that corresponds to the private key configured in the console.
MriverResource.enableVerify(MriverResource.VERIFY_TYPE_YES,"xx");Before you publish the application, enable signature verification. For more information about how to configure signature verification for Mini Program packages, see Configure a mini program package.
Configure the request interval for Mini Program packages
mPaaS lets you configure the request interval for Mini Program packages. You can control the interval using an API.
Mriver.setConfig("h5_nbmngconfig", "{\"config\":{\"al\":\"3\",\"pr\":{\"4\":\"86400\","
+ "\"common\":\"864000\"},\"ur\":\"1800\",\"fpr\":{\"common\":\"3888000\"}},"
+ "\"switch\":\"yes\"}");In this code, \"ur\":\"1800\" sets the global update interval. The default value is 1800, which represents the interval in seconds. You can change this value to a number from 0 to 86400 (0 to 24 hours) to set your global request interval for Mini Program packages. A value of 0 means there is no limit on the request interval.
Do not change other parameters.
Use the mPaaS kernel
Mini Programs use the same-layer rendering capability of the mPaaS kernel to improve the user experience for embedded components, such as WebViews, maps, and videos. For information about how to connect and request the mPaaS kernel, see Connect to the mPaaS kernel.
Publish the mini program
Before you can start a Mini Program, you must first publish it in the mPaaS console. The steps are as follows.
Go to the Mini Program console. Log on to the mPaaS console. In the left navigation pane of the target application, go to Mini Program > Mini Program Release.
Configure a virtual domain name. If this is your first time configuring a virtual domain name, go to Mini Program > Mini Program Release > Configuration Management to configure it. A virtual domain name can be any domain name. We recommend that you use your company's domain name, such as
example.com.Create a Mini Program. In the mPaaS console, perform the following steps:
In the left navigation pane, click Mini Program > Mini Program Release.
On the Mini Program package list page, click New.
In the New Mini Program window, enter the Mini Program ID and name, and then click OK. The Mini Program ID can be any 16-digit number, such as 2018080616290001.
In the Mini Program list, find the new Mini Program and click Add.
In the Basic Information section, complete the following configurations:
Version: Enter the version number of the Mini Program package, such as
1.0.0.0.Client Scope: Select the minimum and maximum versions of the Android client for the Mini Program. Client applications within this version range can start the Mini Program. Otherwise, they cannot. You can enter
0.0.0for the minimum version and leave the maximum version empty. This means that all client versions can start this Mini Program.NoteEnsure that you enter the Android client version, not the Mini Program version.
Icon: Click Select File to upload an icon for the Mini Program package. You must upload an icon when you create a Mini Program for the first time. The following image shows a sample icon:

File: Upload the resource file of the Mini Program package. The file format must be
.zip. We have prepared an mPaaS sample Mini Program (click to download) that you can upload directly.NoteBefore you upload the file, change the name of the
.zipfile and the name of the folder inside the compressed package to the 16-digit ID of the Mini Program.
In the Configuration Information section, complete the following configurations:
Main Entry URL: Required. The home page of the Mini Program. The format of the main entry URL is
/index.html#xxx/xxx/xxx/xxx. The part after the at sign (#),xxx/xxx/xxx/xxx, is the first value in thepagesarray in theapp.jsonfile of the Mini Program. As shown in the following figure, the main entry for the mPaaS sample Mini Program is/index.html#page/tabBar/component/index.
Keep the default values for other configurations.
Select I confirm that the above information is accurate and will not be modified after submission.
Click Submit.
Publish the Mini Program. In the mPaaS console, perform the following steps:
In the left navigation pane, click Mini Program > Mini Program Release > Official Mini Program Package Management.
On the Mini Program package list page, select the Mini Program package and version that you want to publish, and then click Create Release.
In the Create Release taskbar, complete the following configurations:
Release Type: Select the Official release type.
Release Description: Optional.
Click OK to create the release.
Start the mini program
After you complete the preceding steps, use the following code in your Android project to start the sample Mini Program:
Mriver.startApp("2018080616290001");In the code, 2018080616290001 is the Mini Program ID. This is only an example. Use your own Mini Program ID.