Mini Program base libraries

更新时间:
复制 MD 格式

Each base library version requires a minimum client version. Use compatibility checks to handle version differences.

Base libraries and clients

Miniapp features depend on the client version:

  • Each base library version requires a specific minimum client version.

  • Newer base library features may not work on older clients.

Ensure base library compatibility describes how to handle version differences. Use my.SDKVersion to get the current base library version.

Ensure base library compatibility

Older clients do not support newer miniapp components and APIs. Handle compatibility as needed.

Use my.canIUse(String) to check feature availability. my.canIUse reference.

Compatibility examples

New APIs

Check whether a new API is supported:

if (my.getLocation) {
    my.getLocation();
} else {
// If you want users to experience your Mini Program on the latest client version, you can display a prompt.
  my.alert({
    title: 'Prompt',
    content: 'The current version is too old to use this feature. Please upgrade to the latest version.'
  });
}

New API parameters

Check whether a new parameter is supported:

if (my.canIUse('getLocation.object.type')) {
    // Write your subsequent processing logic here.
} else {
    console.log('The current version does not support this parameter')
}

New API return values

Check whether a new return value is supported:

if (my.canIUse('getSystemInfo.return.storage')) {
    // Write your subsequent processing logic here
} else {
    console.log('The current version does not support this return value')
}

New component properties

New properties do not cause errors on older clients. Degrade gracefully:

Page({
    data: {
        canIUse: my.canIUse('button.open-type.share')
    }
})

Base library versions

Base library version

Corresponding baseline version

2.8.9

  • Android: 10.2.3

  • iOS: New Mini Program container baselines cp_change_15200851 and 10.2.3

    Note

    Use the 10.2.3 baseline version for new Mini Program containers.

1.14.1

10.1.68

1.14.1

10.1.60

1.9.0

10.1.32

Integrate the base library

Integration steps vary by baseline version. Confirm your baseline version before proceeding.

iOS

10.2.3 Baseline version

The new miniapp container baselines cp_change_15200851 and 10.2.3 support building miniapp base libraries 2.0.

Note

You must use baseline version 10.2.3 for new miniapp containers.

Android

Baseline versions 10.1.68.7 and later

Set the Provider instance at startup:

H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());
Note

If the client uses an H5 public resource package, inherit TinyAppCenterPresetProvider and merge the public resource package code into the inherited class instance.

10.1.60 series and 10.1.68.6 and earlier baseline versions

  1. Implement the H5AppCenterPresetProvider interface:

     package com.mpaas.demo.nebula;
    
     import com.alipay.mobile.nebula.appcenter.H5PresetInfo;
     import com.alipay.mobile.nebula.appcenter.H5PresetPkg;
     import com.alipay.mobile.nebula.provider.H5AppCenterPresetProvider;
    
     import java.io.File;
     import java.io.InputStream;
     import java.util.HashMap;
     import java.util.HashSet;
     import java.util.Map;
     import java.util.Set;
    
     public class H5AppCenterPresetProviderImpl implements H5AppCenterPresetProvider {
         private static final String TAG = "H5AppCenterPresetProviderImpl";
    
         // Set the dedicated resource package for the miniapp. This ID is fixed and cannot be changed.
         private static final String TINY_COMMON_APP = "66666692";
    
         // The asset folder for the preset package.
         private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator;
    
         // A collection of preset packages.
         private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap();
    
         static {
    
             H5PresetInfo h5PresetInfo2 = new H5PresetInfo();
             // The 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());
             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;
         }
    
         /**
          * Set the ID of the resource package that can be downgraded.
          */
         @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;
         }
     }
  2. Download the miniapp base libraries for your client version. Copy them to the asset folder from the previous step and rename them. The default path is assets/nebulaPreset/66666692.

  3. Set the Provider instance at startup:

     H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());
    Note
    • If the client uses H5 public resource packages, merge the public resource package code into the H5AppCenterPresetProvider instance class.

    • Code examples.