All Products
Search
Document Center

Mobile Platform as a Service:Manage offline packages

Last Updated:Jan 22, 2026

Managing offline packages involves presetting, updating, downloading, installing, and deleting H5 applications. Other operations include using global resource packages, retrieving application information, and verifying security signatures.

Prerequisites

Preset H5 applications

Typically, when an H5 application is opened for the first time, the offline package may not have finished downloading. In this case, the application opens using a fallback URL.

Presetting an H5 application is similar to pre-installing an available H5 application in the installation package released on the client. When a user opens the pre-installed application for the first time, the application can directly use the offline package resources. This improves the user experience.

Note

Preset only core H5 applications. Avoid presetting applications that are not frequently used.

To preset an H5 application, complete the following steps:

  1. From the H5 application publishing console, download the .json configuration file for the H5 application and the offline package to be preset.

  2. Add the .json file and the offline package to the asset folder of the project.

  3. When the application starts, call the preset code to install the application. The following code provides an example:

    MPNebula.loadOfflineNebula("h5_json.json", new MPNebulaOfflineInfo("90000000_1.0.0.6.amr", "90000000", "1.0.0.6"));
    Note
    • This is a blocking call. Do not call the method for built-in offline packages on the main thread.

    • This method can be called only once. If you call it multiple times, only the first call is effective. Therefore, you must pass the information of all offline packages to be preset in a single call.

    • If you have multiple built-in .amr packages, make sure the files exist. If a file does not exist, the installation of other built-in offline packages fails.

Use global resource packages

Nebula global resource packages solve the redundancy problem that occurs when multiple H5 applications use the same resources. For example, a React application uses ReactJS framework code. You can put public resources into a global resource package to reduce the size of H5 applications.

Typically, you must preset a global resource package for a project. Subsequent updates can still be delivered from the H5 application console.

The following code example specifies the offline package with an application ID (appId) of 66666692 as a global resource package. It also presets the assets/nebulaPreset/66666692 offline package. The methods are described as follows:

  • getCommonResourceAppList: Informs the H5 container that the offline package with the specified ID is a global resource package. If you do not configure this ID, the built-in offline package does not take effect even if it is included.

  • getH5PresetPkg: Specifies the path and version of the built-in global resource package. The H5 container loads the resource package from the specified asset resource folder. However, if the server-side finds a higher version, the lower-version built-in package is not loaded. You can also use the loadOffLineNebula method mentioned earlier to preset the global resource package. In this case, you do not need to configure the path and version of the built-in offline package in this method.

    Note

    This method applies only to H5 global resource packages.

  • getTinyCommonApp: Returns only the framework resource package ID for a miniapp. If your global resource package is used only by H5 applications, do not write the public resource package ID in this method.

The following code provides an example of a reference implementation class:

public class H5AppCenterPresetProviderImpl implements H5AppCenterPresetProvider {
    private static final String TAG = "H5AppCenterPresetProviderImpl";

    // Public resource package for the business. Avoid using a prefix of 666666.
    private static final String COMMON_BIZ_APP = "xxxxxxxx";

    // Miniapp-specific resource package. Do not modify.
    private static final String TINY_COMMON_APP = "66666692";

    // The asset folder for preset packages.
    private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator;

    // Collection of preset packages.
    private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap();

    static {

        H5PresetInfo h5PresetInfo2 = new H5PresetInfo();
        // File name in the built-in folder.
        h5PresetInfo2.appId = TINY_COMMON_APP;
        h5PresetInfo2.version = "1.0.0.0";
        h5PresetInfo2.downloadUrl = "";

        NEBULA_LOCAL_PACKAGE_APP_IDS.put(TINY_COMMON_APP, h5PresetInfo2);

    }

    @Override
    public Set<String> getCommonResourceAppList() {
        Set<String> appIdList = new HashSet<String>();
        appIdList.add(getTinyCommonApp());
        appIdList.add(COMMON_BIZ_APP);
        return appIdList;
    }

    @Override
    public H5PresetPkg getH5PresetPkg() {
        H5PresetPkg h5PresetPkg = new H5PresetPkg();
        h5PresetPkg.setPreSetInfo(NEBULA_LOCAL_PACKAGE_APP_IDS);
        h5PresetPkg.setPresetPath(NEBULA_APPS_PRE_INSTALL);
        return h5PresetPkg;
    }

    @Override
    public Set<String> getEnableDegradeApp() {
        return null;
    }

    @Override
    public String getTinyCommonApp() {
        return TINY_COMMON_APP;
    }

    @Override
    public InputStream getPresetAppInfo() {
        return null;
    }

    @Override
    public InputStream getPresetAppInfoObject() {
        return null;
    }
}

Then, call the following code when the application starts:

H5Utils.getH5ProviderManager().setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());

Download H5 applications

MPNebula provides an interface to manually download H5 applications:

    /**
     * Download an offline package
     *
     * @param appId                       The ID of the offline package
     * @param mpaasNebulaDownloadCallback The download callback
     */
    public static void downloadApp(final String appId, final MpaasNebulaDownloadCallback mpaasNebulaDownloadCallback)

Install H5 applications

MPNebula provides an interface to manually install H5 applications:

    /**
     * Install an offline package
     *
     * @param appId                      The ID of the offline package
     * @param mpaasNebulaInstallCallback The installation callback
     */
    public static void installApp(final String appId, final MpaasNebulaInstallCallback mpaasNebulaInstallCallback)

Get application information

You can call a method of `H5AppProvider` to retrieve information about an H5 application:

H5AppProvider provider = H5Utils.getProvider(H5AppProvider.class.getName());
AppInfo appInfo = provider.getAppInfo("10000000");                 // Get the application configuration
boolean isInstalled = provider.isInstalled("10000000", "1.0.0.0"); // Check if a specific version of the application is installed
boolean isAvailable = provider.isAvailable("10000000", "1.0.0.0"); // Check if the offline package for a specific version of the application is downloaded

Verify security signatures

Nebula has an offline package signature verification mechanism to prevent malicious programs from tampering with offline packages downloaded to a device. Enable this mechanism by calling the MPNebula interface to set the signature verification parameters. If you use baseline 10.1.60 or later, you must also enable the container configuration. For more information, see H5 container configuration.

  • Call the MPNebula interface before you open an offline package for the first time. Otherwise, the public key initialization fails. For more information about public and private keys, see Configure offline packages > Key management.

  • Regardless of whether signature verification is enabled on the client, it is forcibly performed on devices that are identified as rooted.

      /**
       * @param publicKey The public key for signature verification
       */
      public static void enableAppVerification(final String publicKey)

Delete local applications

Nebula provides an interface to delete local application information. After the local application information is deleted, the application sends a request to the server-side to download and update the local application information again the next time it is opened.

public class MPNebula {
    // appId is the application ID of the offline package or miniapp.
    public static boolean deleteAppInfo(String appId);
}
Note

The minimum baseline versions that support this API are 10.1.68.8 and 10.1.60.14.