Enterprise Mobile Application Studio (EMAS) allows you to integrate the WindVane or uni-app miniapp container into a native app. This topic describes how to integrate a miniapp container into an Android app.
Prerequisites
The AccessKey, SecretKey, and App Code of a native app are obtained. For more information, see the Configure an app topic in the Application Open Platform (for platform operators) chapter of the User Guide.
The ID of a miniapp is obtained. For more information, see Create a miniapp.
The domain name of Application Open Platform is obtained. The domain name of the demo environment is
emas-publish-intl.emas-poc.com
.
Step 1: Add the Maven repository
In the build.gradle
file located in the project root directory, add the Maven repository.
SDKs for miniapp containers are available in the Maven repository deployed in Apsara Stack. For information about the actual repository URL, account, and password, contact the O&M engineer.
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven {
url 'http://nexus-ce.xxx.com/repository/maven-public/'
credentials {
username = '${username}'
password = '${password}'
}
}
}
}
Step 2: Add dependencies
In the build.gradle
file of the app
project, add the dependencies for the miniapp container.
dependencies{
// The basic SDK for the miniapp container. This dependency is required for both WindVane and uni-app.
implementation 'com.aliyun.emas.suite.core:servicebus:1.0.0'
api "com.aliyun.emas.suite.foundation:mini-app-adapter:1.3.0"
// The SDK for the WindVane miniapp container. If you want to integrate the WindVane miniapp container into the app, include this dependency.
implementation "com.aliyun.emas.suite.foundation:windvane-mini-app:1.3.2"
// The SDK for the uni-app miniapp container. If you want to integrate the uni-app miniapp container into the app, include this dependency.
implementation "com.aliyun.emas.suite.foundation:uniapp-mini-app:1.3.0"
}
If the project uses AndroidX dependencies, make sure that the gradle.properties file in the project root directory contains the following configurations:
android.useAndroidX=true
android.enableJetifier=true
Step 3: Initialize the container
You must initialize the miniapp container before you can use it.
MiniAppInitConfig config = new MiniAppInitConfig.Builder()
.setUseWindVane(true) // Configure this method for a WindVane miniapp.
.setUseUniApp(true) // Configure this method for a uni-app miniapp.
.setAccessKey("ZXZ****") // Obtain the AccessKey from Application Open Platform.
.setSecretKey("3PNJxKtf7/eqUohlG3bI****") // Obtain the SecretKey from Application Open Platform.
.setHost("emas.example.com")// Specify the domain name of Application Open Platform. The value in this sample code is provided for reference only. The domain name of the demo environment is emas-publish-intl.emas-poc.com.
.setAppCode("161160300555671164****") // Obtain the App Code from Application Open Platform.
.build();
IMiniAppService miniAppService = new MiniAppService();
miniAppService.initialize(application, config);
ServiceManager.getInstance().registerService(IMiniAppService.class.getName(), miniAppService);
// The following code provides an example of initialization configurations for the WindVane miniapp container. If you want to integrate the WindVane miniapp container into the app, include the configurations.
WVCamera.registerUploadService(CustomWVUploadService.class);
The JavaScript APIs of WVCamera need to upload local images to servers to obtain image URLs, and then return the image URLs to the miniapp. When you integrate a container into the app, you must register the image upload implementation.
Development Environment Setup
Gradle Version : 6.7.1
Android Gradle Plugin Version : 4.2.2
JDK Version : 8
MinSdkVersion : 16
TargetSdkVersion : 30
The aforementioned configuration serves as a recommended environment setup, which may require updates for compatibility with varying versions.
API reference
For more information, see API reference.