This guide will help developers quickly integrate a minimal functionality mini program SDK to enable mini program launching.
Integration process
1. Configure online repository address
The configuration method depends on the Gradle plugin version used in your project.
For Gradle version earlier than 7.0, see Method 1.
For Gradle version 7.1 and later, see Method 2.
Method 1: For Gradle version earlier than 7.0
Add the following configuration to the project-level build.gradle:
buildscript {
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32'
}
}
allprojects {
repositories {
maven {
url 'https://tcmpp-work-maven.pkg.coding.net/repository/tcmpp/android'
}
}
}
Method 2: For Gradle versions 7.1 and later.
Add the following configuration to the project-level settings.gradle:
pluginManagement {
repositories {
maven {
url 'https://tcmpp-work-maven.pkg.coding.net/repository/tcmpp/android'
}
}
}
dependencyResolutionManagement {
repositories {
maven {
url 'https://tcmpp-work-maven.pkg.coding.net/repository/tcmpp/android'
}
}
}
2. Kotlinp lugin configuration
Configure the Kotlin plugin based on the Gradle plugin version:
Method 1: For Gradle version earlier than 7.0:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
Method 2: For Gradle versions 7.1 and later:
plugins {
id "org.jetbrains.kotlin.android"
id "org.jetbrains.kotlin.kapt"
}
3. Configure packagingoptions
Add the following configuration to the app-level build.gradle:
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/libmarsxlog.so'
pickFirst 'lib/armeabi/libmarsxlog.so'
pickFirst 'lib/armeabi-v7a/libmarsxlog.so'
pickFirst 'lib/arm64-v8a/libv8jni.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
kapt 'com.tencent.tcmpp.android:mini-annotation_processor:${version}'// For version information, Please see Android SDK Updates
implementation 'com.tencent.tcmpp.android:mini_core:${version}'//Please see Android SDK Updates
// mini app end
}
Notes:
The {version} in the configuration should be replaced with the version of the dependency; see Android SDK Updates. If you have used annotationProcessor in your project, you need to change all annotationProcessors to kapt annotators.
After you introduce the dependency of mini program SDK, you can integrate the mini program SDK.
Preparations before integration
1. Get configuration file
The mini program SDK initialization requires a configuration file from the mini program console. Follow these steps:
How to get configuration file:
Log in to the mini program console
Create apps
Fill in the app information
Download configuration file
Note:
Default name of the downloaded configuration file: tcmpp-android-configurations.json
2. Add configuration file to project
After obtaining the configuration file, you need to copy the configuration file to the assets directory of your project.
Note:
Ensure the app package name matches the packageName in the configuration file. Otherwise, the mini program SDK cannot pass the package name verification when running, which will cause the SDK initialization error.
If they do not match, you can:
either change the project package name.
or update the package name in the console and re-download the configuration file.
The packageName field in the configuration file needs to be consistent with the package name of the current project.
3. Add mini program SDK Initialization configuration in source code
Inherit the implementation MiniConfigProxy class;
MiniConfigProxy implementation class, add the following annotation:
@ProxyService(proxy = MiniConfigProxy.class)
Sample code:
@ProxyService(proxy = MiniConfigProxy.class)
public class MiniConfigProxyImpl extends MiniConfigProxy {
@Override
public Application getApp() {
return "app Application";
}
@Override
public MiniInitConfig buildConfig() {
MiniInitConfig.Builder builder = new MiniInitConfig.Builder();
MiniInitConfig config = builder
.configAssetName("tcmpp-android-configurations.json")
.imei("IMEI")
.autoRequestPermission(true)
.debug(true)
.build();
}
}
Note:
Please note that configAssetName of MiniConfig should specify the path and name of the configuration file in the project.
At this point, the mini program SDK is integrated. And now you can open and preview mini programs using the API provided by mini program SDK.
Launch mini programs
To launch a mini program, use the following code:
Note:
The appId is the mini program ID, which you need to obtain from the mini program developers.
TmfMiniSDK.startMiniApp(activity, appId, miniStartOptions);
Was this page helpful?