This doc will guide client developers in integrating a lightweight mini program SDK that allows mini programs to be opened.
Integration process
1. Configure the repository address in settings.gradle
pluginManagement {
repositories {
maven {
url 'https://maven-dev.tcmppcloud.com/fHKFBbEjd/repository/maven-public/'
}
}
}
dependencyResolutionManagement {
repositories {
maven {
url 'https://maven-dev.tcmppcloud.com/fHKFBbEjd/repository/maven-public/'
}
}
}
2. Add Kotlin plugin configuration to build.gradle of the application module
plugins {
id "org.jetbrains.kotlin.android"
id "org.jetbrains.kotlin.kapt"
}
3. Configure packagingOptions in build.gradle of the application module
android {
defaultConfig {
packagingOptions{
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libwechatxlog.so'
pickFirst 'lib/armeabi/libwechatxlog.so'
pickFirst 'lib/armeabi-v7a/libwechatxlog.so'
}
}
}
4. Configure mini program SDK dependencies
dependencies {
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'androidx.core:core-ktx:1.6.0'
//gosn
implementation 'com.google.code.gson:gson:2.8.6'
// ok-http
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
// mini app start
// Annotation processor (required)
kapt 'com.tencent.tcmpp.android:mini_annotation_processor:${version}' // For version information, see Android SDK updates // Core library (required)
implementation 'com.tencent.tcmpp.android:mini_core:${version}' // For version information, see Android SDK updates // Preset base library (optional)
implementation 'com.tencent.tcmpp.android:mini_baselib:${version}' // For version information, see Android SDK updates // mini app end
}
Note:
Replace {version} in the configuration with the corresponding version of the dependencies. For version information, see Android SDK updates. If developers have used the annotationProcessor annotation processor in their original projects, they need to change all annotationProcessor entries to kapt annotation processors.
Once the dependencies for the mini program SDK are added, you can begin integrating the mini program SDK as described in the following sections.
Preparation before integration
1. Obtain the configuration file
The initialization of the mini program SDK relies on a configuration file from the console. Before integrating the mini program SDK, you need to obtain this configuration file.
The process for obtaining the configuration file is as follows:
1.1 Log in to the console
1.2 Create a superapp
1.3. Fill in the superapp information
Required information:
Superapp name: Supports 3-64 characters including a-z, A-Z, 0-9, spaces and some special symbols ("+", "=", ",", ".", "@", "-", "_").
Optional information:
Superapp description: Brief introduction of the superapp, primarily for internal reference.
Superapp icon: Supports uploading square images in .jpg or .png format, with a resolution of 128 × 128 and a file size under 2 MB. If the icon is not uploaded, the system default icon will be used.
Scheme: Only supports lowercase letters and numbers, up to 64 characters. Once the scheme is configured, the QR code of the mini program (or mini game) will include this scheme. Using the phone system’s built-in scanning function, users can directly launch superapp and open the mini program (or mini game).
1.4 Enter the superapp package name
The following fields need to be filled in when adding the package name/bundle ID:
Type: Once selected, the type cannot be changed. Package names for non-production types are only used for superapp test versions and have a monthly device usage limit (up to 500 devices).
Package name/bundle ID: Only supports lowercase letters (a-z), numbers (0-9), dots (.), and hyphens (-), up to 255 characters. It is recommended to use reverse domain name notation, such as com.example.myapp.
Download URL: Only supports uppercase letters (A-Z), lowercase letters (a-z), numbers (0-9), dots (.), hyphens (-), and slashes (/), up to 2,048 characters.
1.5 Download the configuration file
Note:
The default name of the downloaded configuration file is tcsas-android-configurations.json.
2. Add the configuration file to the project
After obtaining the configuration file, you need to copy the configuration file to the assets directory of your project.
Note:
Ensure the superapp package name matches the one configured in the console. Otherwise, the mini program SDK will fail to validate the package name at runtime, leading to SDK errors.
3. Add mini program SDK initialization configuration in the source code
Extend and implement the MiniConfigProxy class.
Add the following annotations for the implementation class of MiniConfigProxy:
@ProxyService(proxy = MiniConfigProxy.class)
Example:
@ProxyService(proxy = MiniConfigProxy.class)
public class MiniConfigProxyImpl extends MiniConfigProxy {
@Override
public Application getApp() {
return "your superapp Application";
}
@Override
public MiniInitConfig buildConfig() {
MiniInitConfig.Builder builder = new MiniInitConfig.Builder();
MiniInitConfig config = builder
.configAssetName("tcsas-android-configurations.json")
.autoRequestPermission(true)
.debug(true)
.build();
return config;
}
}
Note:
2. Since the SDK initially retrieves the superapp's Application instance from an internal ContentProvider, it is recommended to cache the Application instance in the Application.attachBaseContext method. This prevents the SDK from obtaining a null Application instance due to timing issues.
At this point, the integration of the mini program SDK is complete. The next step is to use the APIs provided by the mini program SDK to open and preview mini programs.
Open a mini program
To open a mini program, use the following code:
Note:
The appid is the mini program appid, which needs to be obtained from the mini program developer.
TmfMiniSDK.startMiniApp(activity, appId, new MiniStartOptions());
Implement the image loading API
To allow superapps to centrally manage and control image loading, the mini program SDK does not provide a default image loading feature. Instead, it offers a proxy API for superapps to implement image loading. If a superapp does not implement image loading, the following features may display abnormally:
Mini program icons in the capsule panel
Mini program icons in authorization pop-ups
Mini program icons on the loading page
Mini program icons on the About page
The video component cover
The cover-image image
The profile photo
Mini program data is stored separately by user account
If your superapp supports multiple user logins and you need to prevent mini program sandbox data from being shared across different users, you need to implement the IMiniAppProxy.getAccount() method to return a differentiated user ID. This enables sandbox data to be isolated and stored per account.