All Products
Search
Document Center

Mobile Platform as a Service:Getting started

Last Updated:Oct 18, 2023

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:

  1. Select Baseline.

    1. Add the 10.2.3 baseline.

    2. Add the mini program component.

  2. Initialize configurations.

    1. Configure parameters for metadata recovery.

    2. The signature verification configuration of the mini program.

    3. Apply the UC kernel.

  3. Publish the mini program.

    1. Enter the background of the mini program.

    2. Configure the virtual domain name.

    3. Create a mini program.

    4. Publish the mini program.

  4. Start a mini program.

The operation of each step will be described in detail below.

Select Baseline

  1. Add the 10.2.3 baseline.

  2. Add the mini program component.

Initialize the SDK

Initialize mPaaS

Use the mPaaS framework to initialize the instance (Recommended).

  1. 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();
        }
    }
  2. Add meta configurations to the AndroidManifest.xml.

    <meta-data
        android:name="mpaas.init.param"
        android:value="com.xxx.xxx.MriverInitImpl" />
  3. 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");
Note

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

Important

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.

Note

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.

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

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

  3. Create a mini program. Go to the mPaaS console and perform the following operations:

    1. In the left-side navigation pane, choose Mini program > Mini Program Release.

    2. On the page that appears, click Create.

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

    4. In the mini program app list, find the new mini program app and click Add.

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

        Note

        Be 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: 6

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

        Note

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

    6. 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 the xxx/xxx/xxx/xxx after# is the first value in the pages in the app.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. 7

      • Keep the default settings for other configurations.

    7. Select Make sure that the preceding information is accurate and do not modify it after you submit it.

    8. Click Submit.

  4. Release the mini program. Go to the mPaaS console and complete the following steps:

    1. In the left-side navigation pane, choose Mini program > Mini Program Release > Official mini program package management.

    2. On the Mini Program Package page, select the mini program package and version that you want to release, and click Create release.

    3. 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");
Note

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.