# Android Quick Integration
Integration Sample Code
We provide a DEMO project. Developers can obtain integration sample code from Github (International) (opens new window) or Gitee (China) (opens new window).
This document is a quick integration guide. It only contains the necessary SDK initialization configuration and example code for starting a Mini-Program using an AppId. For more features, please refer to the detailed integration document SDK Integration. Additionally, integration methods may vary across different SDK versions. It is recommended to check the detailed configuration tutorial.
# 1. Obtain Credentials
Please Note
Integrating the SDK requires first creating an application and binding a Mini-Program in the FinClip platform. After obtaining the application-specific SDK KEY and SDK SECRET, you can fill in the corresponding parameters during SDK integration. When opening a Mini-Program, the SDK will automatically initialize and verify whether the SDK KEY, SDK SECRET, and BundleID (Application ID) are correct.
You can 【Click Here】 to view how to obtain the required SDK KEY and SDK SECRET. Please ensure the parameters filled in during SDK integration are correct; otherwise, the Mini-Program may fail to open.
# 2. Import SDK
# 2.1 Via Gradle Dependency
# 2.1.1 Configuration Required in the Project's build.gradle
Since part of the SDK code is written in Kotlin, the Kotlin Gradle plugin needs to be added to the project's `build.gradle`:
```groovy
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
The complete configuration of the project's build.gradle is as follows:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.5.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://gradle.finogeeks.club/repository/applet/"
credentials {
username "applet"
password "123321"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
# 2.1.2 Depend on SDK in Gradle
Add the dependency for finapplet in the dependencies section of the gradle file:
implementation 'com.finogeeks.lib:finapplet:2.43.7' // If using other versions, it is recommended to check the detailed configuration tutorial. Configurations may vary across versions.
Therefore, you need to add the doNotStrip configuration in the build.gradle of the App module :
packagingOptions {
// libsdkcore.so is obfuscated and cannot be stripped; otherwise, an error will occur when loading the dynamic library
doNotStrip "*/x86/libsdkcore.so"
doNotStrip "*/x86_64/libsdkcore.so"
doNotStrip "*/armeabi/libsdkcore.so"
doNotStrip "*/armeabi-v7a/libsdkcore.so"
doNotStrip "*/arm64-v8a/libsdkcore.so"
}
The complete configuration is as follows:
apply plugin: 'com.android.application'
android {
buildToolsVersion '28.0.3'
compileSdkVersion 28
defaultConfig {
applicationId "com.finogeeks.finappletdemo"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
// libsdkcore.so is obfuscated and cannot be stripped; otherwise, an error will occur when loading the dynamic library
doNotStrip "*/x86/libsdkcore.so"
doNotStrip "*/x86_64/libsdkcore.so"
doNotStrip "*/armeabi/libsdkcore.so"
doNotStrip "*/armeabi-v7a/libsdkcore.so"
doNotStrip "*/arm64-v8a/libsdkcore.so"
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.finogeeks.lib:finapplet:2.43.7' // If using other versions, it is recommended to check the detailed configuration tutorial. Configurations may vary across versions.
}
# 2.2 Configure Obfuscation Rules
After integrating the SDK, to prevent certain non-obfuscatable code within the SDK from being obfuscated, add the following configuration to the project's obfuscation rules configuration file:
-keep class com.finogeeks.** {*;}
# 3. SDK Initialization
We strongly recommend initializing the SDK in the Application. The parameters required for initializing the SDK are as follows (SDK initialization only needs to be called once; avoid repeated calls).
Call the initialization interface to initialize the SDK:
FinAppClient.INSTANCE.init(this, config, callback);
# 3.1 SDK Initialization Multi-Process Handling
The SDK uses a multi-process mechanism, where each Mini-Program runs in an independent process (i.e., one Mini-Program corresponds to one process). When initializing the SDK, it is particularly important to note: When a Mini-Program process is created, no initialization operations need to be performed, not even the Mini-Program SDK initialization, within the Mini-Program process.
For example: If the application uses some third-party libraries that need to be initialized when the application starts, then when performing initialization in the Application, these third-party libraries should only be initialized if the current process is the Host-App process; Mini-Program processes do not need to initialize these libraries.
Therefore, before initializing the SDK, you must determine which process the current process is. If it is a Mini-Program process, do not perform any operations:
if (FinAppClient.INSTANCE.isFinAppProcess(this)) {
return;
}
The above describes the entire SDK initialization process. The complete code is as follows:
package com.example.finogeeks.appletdemo;
import android.os.Process;
import android.support.multidex.MultiDexApplication;
import android.text.TextUtils;
import android.widget.Toast;
import com.example.finogeeks.appletdemo.api.ApiOpenPage;
import com.example.finogeeks.appletdemo.api.ApiOpenPageForResult;
import com.example.finogeeks.appletdemo.api.DrawModule;
import com.example.finogeeks.appletdemo.util.ProcessUtilKt;
import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.lib.applet.client.FinAppConfig;
import com.finogeeks.lib.applet.interfaces.FinCallback;
/**
* The application's {@link android.app.Application}
*/
public class AppletApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
if (FinAppClient.INSTANCE.isFinAppProcess(this)) {
// Mini-Program processes do not perform any initialization operations
return;
}
// Server information collection
List<FinStoreConfig> storeConfigs = new ArrayList<>();
// Server information
FinStoreConfig storeConfig = new FinStoreConfig(
"SDK Key information", // SDK Key
"SDK Secret information", // SDK Secret
"Server 1 address", // Server address
"Server 1 data reporting server address", // Data reporting server address
"/api/v1/mop/", // Server interface request route prefix
"",
"Encryption method", // Encryption method, SM for GuoMi, MD5 for md5 (recommended)
false
);
storeConfigs.add(storeConfig);
FinAppConfig config = new FinAppConfig.Builder()
.setFinStoreConfigs(storeConfigs) // Server information collection
.build();
FinAppClient.INSTANCE.init(this, config, new FinCallback<Object>() {
@Override
public void onSuccess(Object result) {
}
@Override
public void onError(int code, String error) {
Toast.makeText(AppletApplication.this, "SDK initialization failed", Toast.LENGTH_SHORT).show();
}
@Override
public void onProgress(int status, String error) {
}
});
}
}
# 4. Start Mini-Program
After publishing the Mini-Program on the platform, we can open the Mini-Program by calling the start Mini-Program interface in the SDK. The code to start the Mini-Program is as follows:
// Build request
RemoteFinAppletRequest request = new RemoteFinAppletRequest(apiServer, appId);
// Or use the following method to omit the server environment address configuration; the first server environment address configured during SDK initialization will be used by default
RemoteFinAppletRequest request = IFinAppletRequest.Companion.fromAppId(appId);
// Open Mini-Program
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, request, callback);