The new mini program container is only available in the 10.2.3 baseline version, and only supports the integration mode of mPaaS native AAR. For more information, see Native AAR.
Prerequisites
Before you integrate a new mini program to Android, make sure that you have activated mPaaS and use native AAR to integrate to mPaaS.
Procedure
The following table describes how to integrate a new container to a mini program:
Add the 10.2.3 baseline.
Add the mini program component.
Configure parameters for metadata recovery.
The signature verification configuration of the mini program.
Apply the UC kernel.
Enter the background of the mini program.
Configure the virtual domain name.
Create a mini program.
Publish the mini program.
The operation of each step will be described in detail below.
Select Baseline
Add the 10.2.3 baseline.
Add the mini program component.
Initialize the SDK
Initialize mPaaS
Use the mPaaS framework to initialize the instance (Recommended).
Add initialization code to the
Application
.// Initialize public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // mPaaS initialization callback settings QuinoxlessFramework.setup(this, new IInitCallback() { @Override public void onPostInit() { // Initialize the logic of other mPaaS components. } }); } @Override public void onCreate() { super.onCreate(); // Initialize mPaaS. QuinoxlessFramework.init(); } }
Add meta configurations to the
AndroidManifest.xml
.<meta-data android:name="mpaas.init.param" android:value="com.xxx.xxx.MriverInitImpl" />
Add com.xxx.xxx.MriverInitImpl to achieve MPInitParamManifest.
public class MriverInitImpl implements com.mpaas.MPInitParamManifest { @Override public MPInitParam initParam() { MriverInitParam mriverInitParam = createInitParams(); return MPInitParam.obtain().addComponentInitParam(mriverInitParam); } }
Use MPInit to initialize mPaaS
Initialize mPaaS and add the following code to the Application
.
MP.init(this, createInitParams());
MPInitParam createInitParams() {
final MriverInitParam mriverInitParam = MriverInitParam.getDefault();
mriverInitParam.setMriverInitCallback(new MriverInitParam.MriverInitCallback() {
@Override
public void onInit() {
MPLogger.setUserId("MPTestCase");
if (com.alibaba.ariver.kernel.common.utils.ProcessUtils.isMainProcess()) {
// Related configuration of the mini program, such as JSAPI and titlebar.
Log.i("MriverApp", "init1");
Mriver.setConfig("mr_use_inner_net", "YES");
Mriver.setConfig("mr_request_support_gzip", "true");
Mriver.setConfig("mr_showShareMenuItem", "YES");
Mriver.setConfig("mriver_openlocation_hidden_default", "0");
Mriver.setConfig("mriver_support_chooseFile", "YES");
Mriver.setConfig("ta_worker_init_low_version_compat", (Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 21) ? "YES" : "NO");
MriverEngine.registerBridge(ShareApiBridgeExtension.class);
MriverEngine.registerBridge(SnapshotScreenApiBridgeExtension.class);
Mriver.enableAPM();
List<String> miniAppPoint = new ArrayList<>();
miniAppPoint.add(PageResumePoint.class.getName());
miniAppPoint.add(PageEnterPoint.class.getName());
Mriver.registerPoint(PageLifeCycleExtension.class.getName(), miniAppPoint);
RVProxy.set(PrepareNotifyProxy.class, new PrepareNotifyProxy() {
@Override
public void notify(String s, PrepareStatus prepareStatus) {
}
@Override
public void apmEvent(final String s, final String s1, final String s2, final String s3, final String s4) {
mUIHandler.post(new Runnable() {
@Override
public void run() {
if (APMActivity.logs == null) {
APMActivity.logs = new StringBuilder();
}
APMActivity.logs.append(s).append(" ").append(s1).append(" ").append(s2).append(" ").append(s3).append(" ").append(s4).append("\n");
if (TextUtils.equals(s, "MiniAppStart")
|| TextUtils.equals(s, "MiniPage_Load_T2")) {
Toast.makeText(MRiverApp.sApp, "startTime: " + s4, Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
Log.i(TAG, "registerPlugin");
MPNebula.registerH5Plugin(
PagePlugin.class.getName(),
null,
"page",
new String[]{"myapi2", H5Plugin.CommonEvents.H5_SESSION_EXIT, H5Plugin.CommonEvents.H5_PAGE_CLOSED, H5Plugin.CommonEvents.H5_PAGE_FINISHED, H5Plugin.CommonEvents.H5_PAGE_SHOULD_LOAD_URL}
);
MriverEngine.enableDebugConsole();
Mriver.setConfig("mriver_show_debug_menu_all", "YES");
Log.i("TTAATT", "hasInited");
}
@Override
public void onError(Exception e) {
Log.i("MriverApp", "init2");
}
});
mriverInitParam.setUCInitCallback(new MriverInitParam.UCInitCallback() {
@Override
public void onInit() {
sHasUCInit = true;
Log.i("TTAATT", "hasInitedUC");
}
@Override
public void onError(Exception e) {
}
});
return MPInitParam.obtain().setCallback(this).addComponentInitParam(mriverInitParam);
}
Mini program signature verification configuration
The mini program container provides the package signature verification function. By default, the debug package is disabled and the release package is enabled. You can control the package signature through APIs.
// Disable the signature.
MriverResource.disableVerify();
// Enable signature, where xx is the public key corresponding to the private key configured in the background.
MriverResource.enableVerify(MriverResource.VERIFY_TYPE_YES,"xx");
Before you go online, we recommend that you enable signature verification. For more information about how to configure signature verification for mini program packages, see Configure Mini Program package.
Configure the time interval for mini program package requests
mPaaS supports configuring the request interval of mini program packages, which can be controlled through APIs.
Mriver.setConfig("h5_nbmngconfig", "{\"config\":{\"al\":\"3\",\"pr\":{\"4\":\"86400\","
+ "\"common\":\"864000\"},\"ur\":\"1800\",\"fpr\":{\"common\":\"3888000\"}},"
+ "\"switch\":\"yes\"}");
\"ur\":\"1800\"
is the value used to set the global update interval, and 1800
is the default value, which represents the interval duration in seconds. You can modify this value to set your global mini program package request interval in the range of 0 to 86400 seconds (that is, 0 to 24 hours, 0 means no request interval limit).
Please do not modify other parameters.
Apply for UC kernel
Before you use a mini program, you must apply for and configure UC kernel. If you do not have UC kernel, you cannot use some of the capabilities of an Android mini program. For more information, see Apply for UC kernel.
Due to changes in product policies, you cannot apply for UC keys publicly from December 1, 2022.
With the UC kernel, mini programs can have the same-layer capabilities, such as embedded webview and embedded map, and have a better rendering experience.
Release mini program
Before starting the mini program, you need to release the mini program in the mPaaS console.
Enter the background of the mini program. Log on to the mPaaS console. In the left-side navigation pane, choose Mini program > Mini Program Release.
Configure the virtual domain name. If this is the first time to configure a virtual domain name, you must first configure a virtual domain name on the Mini program > Mini Program Release > Manage configuration page. The virtual domain name can be any domain name. We recommend that you use your enterprise domain name, such as
example.com
.Create a mini program. Go to the mPaaS console and perform the following operations:
In the left-side navigation pane, choose Mini program > Mini Program Release.
On the page that appears, click Create.
In the Create mini program dialog box, enter the ID and name of the mini program and click OK. The mini program ID is any 16-bit number, for example, 2018080616290001.
In the mini program app list, find the new mini program app and click Add.
In the Basic Information section, configure the following parameters:
Version: Enter the version number of the mini program package, for example,
1.0.0.0
.Client Range: Select the minimum and maximum versions of the Android client corresponding to the mini program app. The client App within this range can start the corresponding mini program, otherwise it cannot be started. Here, the minimum version can be filled in
0.0.0
, and the maximum version can be left unfilled, which means that all versions of the client can start this mini program.NoteBe sure to enter the client version of Android, not the mini program version.
Icon: Click the Select File icon to upload the mini program package. You must upload the icon when you create the mini program for the first time. An example icon is as follows:
File: Upload the mini program package resource file. The file format is
.zip
. We have prepared a mPaaS sample mini program (click here to download ), which can be uploaded directly.NoteBefore you upload the mini program, you must change the
.zip
file name and folder name in the package to the 16-digit ID of the mini program.
In the configuration information bar, complete the following configurations:
Main Portal URL: required. The homepage of the mini program. The format of the main entry URL is:
/index.html#xxx/xxx/xxx/xxx
, where thexxx/xxx/xxx/xxx
after#
is the first value in thepages
in theapp.json
of the mini program. As shown in the following figure, the main entry point of the mPaaS mini program is:/index.html#page/tabBar/component/index
.Keep the default settings for other configurations.
Select Make sure that the preceding information is accurate and do not modify it after you submit it.
Click Submit.
Release the mini program. Go to the mPaaS console and complete the following steps:
In the left-side navigation pane, choose Mini program > Mini Program Release > Official mini program package management.
On the Mini Program Package page, select the mini program package and version that you want to release, and click Create release.
In the Create Release pane, configure the following settings:
Release Type: Select Official.
Release Description: Optional.
Click OK.
Start mini program
After you complete the preceding steps, run the following code to start the sample mini program in the Android project:
Mriver.startApp("2018080616290001");
The 2018080616290001
in the preceding code is the ID of the mini program. This is only an example in this article. Enter the ID of your mini program.