Instant Messaging
Getting Started
Account Integration and Login
Basic Messaging
Group Features
Chat Room
Chat Room Tags
Multi-device Login
Run the demo
Implement messaging
Integrate IM
Integrate SDK
NOS storage
Message options
Audio messages
Broadcast messages
Read receipt
Unsend a message
Resend and forward a message
Update a message
Recent sessions
User relation
Message history
System notifications
Push service for Android
Push service for iOS
Manage groups
Manage members
Manage messages
Activate chat room
Chat room
Dev support
Server-side session
API Reference
APIs for Flutter
Work with the Console
Create a project
Upgrade to IM Pro
Create Accounts

SDK Integration

Update time: 2023/01/18 16:57:35

Instant Messaging (IM) is a stable messaging service based on the communication technology provided by CommsEase. You can use IM to build robust chatting features for your apps. Instant Messaging (NIM) SDK for Flutter offers a full-fledged instant messaging framework using Flutter, wrap nternal complexities, and provides easy-to-use APIs to facilitate quick integration with your applications. The SDK for Flutter supports Android and iOS.


  • NIM SDK for Flutter is downloaded
  • Create Project in the CommsEase console and get AppKey and App Secret.
  • CommsEase IM accounts are registered. CommsEase IM accounts (account or accid) are used to log on to NIM SDK.
  • You have contacted the business manager to activate add-on services, such as data sync as required.

Development environment

Make sure your development environment meets the following requirements:

  • Flutter-dart 2.12.0 or later.

  • Development environment for each platform:

    • Android Studio 3.5 or later
    • Android 4.4 API 19 or later
    • 1.5.21 or later for kotlin-gradle-plugin.
    • Xcode 11.0 and later.
    • iOS 9.0 or later
    • Your project must have a valid signature.
    Windows (Beta)
    • Windows 7 SP1 or later (x86-64 based 64-bit OS).
    • Visual Studio 2019
    • CMake 3.10 or later
    macOS (Beta)
    • Xcode 11.0 and later.
    • macOS 10.14 or later.
    • Your project must have a valid signature.
    Web (Beta)
    • You have installed Visual Studio Code with the flutter plugin installed.
    • Proficient in using Flutter commands.

    Windows, macOS, and Web are currently still in beta and in closed testing, so stay tuned.

Integrate the SDK

Integrate the SDK for Android, iOS, Windows, or macOS

NIM SDK for Flutter has been published to the pub library. You can download, and update the newest SDK by configuring pubspec.yaml .

  1. Add the following dependencies to your project's pubspec.yaml file.

    nim_core: ^1.1.0 
  2. Download the dependency packages by running the following command in the Shell or IDE.

    flutter pub get
Integrate the SDK for Web
  1. Add the following dependencies to your project's pubspec.yaml file.

    nim_core: ^1.1.0 
  2. Run the following command to download dependencies using Shell or IDE:

    flutter pub get
  3. Create a web folder and create an index.html file in the web folder. The template of the index file is as follows:

    The link in the following template is the link of the front-end js resource package of the Flutter SDK for Web. You must replace the link for new upgrades. Contact technical support for the link of the latest version.

    <!DOCTYPE html>
        <meta charset="UTF-8" />
        <meta content="IE=Edge" http-equiv="X-UA-Compatible" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        content="Flutter web"
        <title>You page title</title>
        // The value below is injected by flutter build, do not touch.
        var serviceWorkerVersion = null;
        <script src="flutter.js"></script>
        <!-- The link below is the link of the front-end js resource package of the Flutter SDK for Web. You must replace the link for new upgrades. Contact technical support for the link of the latest version.
        var jsConfig = [
        window.onload = function () {
            // Download main.dart.js
            try {
                serviceWorker: {
                    serviceWorkerVersion: serviceWorkerVersion,
                .then(function (engineInitializer) {
                return engineInitializer.initializeEngine()
                }).then(appRunner => {
                require(jsConfig, (RootService) => {
                    window.$flutterWebGlobal = {
                    rootService: new RootService.default(),
            } catch (error) {
        async function dartCallNativeJs(callInfo = {}) {
            const { serviceName, method, params, successCallback, errorCallback } =
            try {
            console.log('dartCallNativeJs: ', callInfo)
            const service = window.$flutterWebGlobal.rootService[serviceName];
            if (!service) {
                throw new Error(`You do not implement this service: ${serviceName}`);
            if (!service[method]) {
                throw new Error(`This method: ${method} is not implemented on this service: ${serviceName}`);
            // Delete serviceName from the parameter
            if (params.hasOwnProperty('serviceName')) {
                delete params.serviceName;
            const res = await service[method](params);
            } catch (error) {
            console.error('dartCallNativeJs failed: ', error)
            throw error
  4. Test whether the SDK for Web is integrated by running the flutter run -d chrome command. If you can see the following page and Chrome console call log after running the command, the integration is successful.


Compilation and deobfuscation configuration for Android

After integrating the SDK for Flutter, you must add the following configuration for Android.

Compilation configuration

  1. Use kotlin-gradle-plugin and add the following configuration to the build.gradle file in the project root directory.

    //file: build.gradle
    buildscript {
        ext.kotlin_version = '1.5.21'
        repositories {
        dependencies {
            classpath ''
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  2. Configure packagingOptions in app/build.gradle. Example is as follows:

        //file: app/build.gradle
        // New: enable the Kotlin plugin
        apply plugin: 'kotlin-android'
        android {
            // Other settings
            packagingOptions {
                pickFirst 'lib/x86/'
                pickFirst 'lib/x86_64/'
                pickFirst 'lib/armeabi-v7a/'
                pickFirst 'lib/arm64-v8a/'

Deobfuscation configuration

Add the required classes of NIM SDK for Flutter to the anti-obfuscation list in the file.

-dontwarn com.netease.**
-keep class com.netease.** {*;}
-dontwarn org.apache.lucene.**
-keep class org.apache.lucene.** {*;}
-keep class net.sqlcipher.** {*;}
Was this topic helpful?
  • Prerequisites
  • Development environment
  • Integrate the SDK
  • Compilation and deobfuscation configuration for Android
  • Compilation configuration
  • Deobfuscation configuration