Skip to content

Quickstart(Android)

This topic introduces how to quickly set up the Androdi MiniProgram SDK and implement basic mini-program capabilities.

Get started

To get started with MiniProgram SDK, perform the following actions:

Step 1: Get SDK Key and SDK SECRET

Log in to FinClip Mini Program Platform, go to the App Manage page, create an application, then click to add Bundle ID, enter your project bundle id. After the creation is complete, You can find SDK KEY,SDK SECRET of the application will be generated.

Step 2. Import SDK

2.1 Relying on Gradle

2.1.1 Configure the build.gradle of the project

Add the address of the maven repository in the build.gradle of the project:

groovy
maven {
    url "https://gradle.finogeeks.club/repository/applet/"
    credentials {
    username "applet"
    password "123321"
    }
}

Due to some code in the SDK being written using Kotlin, it is necessary to add Kotlin's gradle plugin to the 'build. gradle' of the project:

groovy
classpath "org. jtbrains. kotlin: kotlin gradle plugin: 1.3.61"

The complete configuration of build.gradle of the project is as follows:

groovy
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 Dependency on SDK in Gradle

Add a dependency on finapplet in the dependencies section of the gradle file:

groovy
implementation 'com.finogeeks.lib:finapplet:2.43.7' // If you use other versions, it is recommended to check the detailed configuration tutorial. The configuration may vary from version to version.

It is necessary to add the doNotStrip configuration in the build. gradle section under the:

groovy
packagingOptions {
    // Libsdkcore.so is reinforced and cannot be compressed, otherwise an error will be reported when the dynamic library is loaded.
    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:

groovy
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 reinforced and cannot be compressed, otherwise an error will be reported when the dynamic library is loaded.
        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 review the detailed configuration tutorial. The configuration may vary between different versions.
}

2.2 Configure obfuscation rules

After integrating SDK, to avoid confusion of some codes in SDK that cannot be confused, you need to add the following configuration to the obfuscation rule configuration file of the project:

groovy
-keep class com.finogeeks.** {*;}

Step 3. SDK initialization

We strongly recommend initializing the SDK in Application. The parameters that need to be passed in to initialize the SDK are as follows (SDK initialization only needs to be called once, and repeated calls should be avoided).

Calling the initialization interface to initialize the SDK:

java
FinAppClient.INSTANCE.init(this, config, callback);

3.1 SDK initializes multiprocess processing

SDK is implemented using a multi-process mechanism. Each Mini Program runs in an independent process, that is, one Mini Program corresponds to one process.

When initializing SDK, you should pay special attention to: the Mini Program process does not need to perform any initialization operations when it is created, even the initialization of Mini Program SDK does not need to be performed in the Mini Program process.

For example, the application uses some third-party libraries that need to be initialized when the application starts. When initializing in Application, these third-party libraries need to be initialized only if the current process is the host process, and the Mini Program process does not need to initialize these libraries.

Before initializing the SDK, it is necessary to determine which process the current process is. If it is a mini program process, no operations will be performed:

java
if (FinAppClient.INSTANCE.isFinAppProcess(this)) {
    return;
}

This is the whole process of initializing SDK. The complete code is as follows:

java
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;

/**
 * 应用的{@link android.app.Application}
 */
public class AppletApplication extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();

        if (FinAppClient.INSTANCE.isFinAppProcess(this)) {
            // The mini program process does not perform any initialization operations
            return;
        }

        // Server information collection
		List<FinStoreConfig> storeConfigs = new ArrayList<>();
		// Server information
		FinStoreConfig storeConfig = new FinStoreConfig(
        		"SDK Key信息",   // SDK Key
        		"SDK Secret信息",   // SDK Secret
        		"服务器1的地址",   // Server address
        		"服务器1的数据上报服务器地址",   // Address of data escalation server
        		"/api/v1/mop/",   // Server interface request routing prefix
        		"",
        		"加密方式",   // Encryption method: SM,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初始化失败", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onProgress(int status, String error) {

            }
        });
    }
}

Step 4. Start Mini Program

After Mini Program is launched on the platform, we can open Mini Program by calling the API in SDK that starts Mini Program. The code to start Mini Program is as follows:

java
// Build request
RemoteFinAppletRequest request = new RemoteFinAppletRequest(apiServer, appId);
// Alternatively, the configuration of the server environment address can be omitted using the following method. By default, the first server environment address configured during SDK initialization will be used
RemoteFinAppletRequest request = IFinAppletRequest.Companion.fromAppId(appId);
// Open mini program
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, request, callback);