Mobile Development 14 min read

Quickly Integrate NetEase Cloud Chatroom SDK into Android Apps

This guide walks developers through the complete Android integration of NetEase Cloud's chatroom SDK, covering Gradle setup, required permissions, ProGuard rules, SDK initialization, entering and leaving chatrooms, message handling, and UI component usage with practical code examples.

NetEase Smart Enterprise Tech+
NetEase Smart Enterprise Tech+
NetEase Smart Enterprise Tech+
Quickly Integrate NetEase Cloud Chatroom SDK into Android Apps

Integration Overview

Since 2000, chatrooms have been used in various scenarios such as small classes, large interactive classes, gaming, and live streaming. This article explains how to quickly integrate the NetEase Cloud chatroom SDK on Android, covering basic SDK integration, permission configuration, ProGuard settings, functional usage, and UI component integration.

1. SDK Integration

Step 1: Gradle Integration

allprojects {
    repositories {
        jcenter() // or mavenCentral()
    }
}

In the app module build.gradle, add NDK support:

android {
   defaultConfig {
       ndk {
           abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
       }
   }
}

Then add the required dependencies (example uses version 8.6.0):

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // Core SDK (required)
    implementation 'com.netease.nimlib:basesdk:8.6.0'
    // Chatroom SDK (required)
    implementation 'com.netease.nimlib:chatroom:8.6.0'
}

Note: All NetEase component versions must be consistent. SDK download link: https://yunxin.163.com/im-sdk-demo

2. Permission & Component Configuration

Add the following permissions to AndroidManifest.xml (replace com.netease.nim.demo with your package name):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.netease.nim.demo">
    <!-- Network permissions -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <!-- Storage permissions -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- Media permissions -->
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <permission android:name="com.netease.nim.demo.permission.RECEIVE_MSG" android:protectionLevel="signature"/>
    <uses-permission android:name="com.netease.nim.demo.permission.RECEIVE_MSG"/>
    <application ...>
        <meta-data android:name="com.netease.nim.appKey" android:value="key_of_your_app"/>
        <service android:name="com.netease.nimlib.service.NimService" android:process=":core"/>
        <service android:name="com.netease.nimlib.service.NimService$Aux" android:process=":core"/>
        <service android:name="com.netease.nimlib.job.NIMJobService" android:exported="true" android:permission="android.permission.BIND_JOB_SERVICE" android:process=":core"/>
        <receiver android:name="com.netease.nimlib.service.NimReceiver" android:process=":core" android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>
        <!-- other components omitted for brevity -->
    </application>
</manifest>

ProGuard Rules (if obfuscation is used)

-dontwarn com.netease.**
-keep class com.netease.** { *; }
# Lucene plugin
-dontwarn org.apache.lucene.**
-keep class org.apache.lucene.** { *; }
# SQLCipher database
-keep class net.sqlcipher.** { *; }

3. Functional Usage

Step 1: Initialize SDK

public class NimApplication extends Application {
    @Override
    public void onCreate() {
        SDKOptions sdkOptions = new SDKOptions();
        NIMClient.init(this, null, sdkOptions);
    }
}

Step 2: Enter Chatroom

// roomId is the chatroom ID
EnterChatRoomData data = new EnterChatRoomData(roomId);
data.setAppKey(appKey);
data.setIndependentMode(new ChatRoomIndependentCallback() {
    @Override
    public List<String> getChatRoomLinkAddresses(String roomId, String account) {
        // Request chatroom addresses from your server
        return "list of addresses from server";
    }
}, account, token);
NIMClient.getService(ChatRoomService.class)
    .enterChatRoomEx(data, 1)
    .setCallback(new RequestCallback<EnterChatRoomResultData>() {
        @Override
        public void onSuccess(EnterChatRoomResultData result) {
            Toast.makeText(MainActivity.this, "onSuccess", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onFailed(int code) {
            Toast.makeText(MainActivity.this, "onFailed", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onException(Throwable exception) {
            Toast.makeText(MainActivity.this, "onException", Toast.LENGTH_SHORT).show();
        }
    });

Step 3: Send and Receive Messages

// Send a text message
String roomId = "roomId";
String text = "This is a chatroom text message";
ChatRoomMessage message = ChatRoomMessageBuilder.createChatRoomTextMessage(roomId, text);
NIMClient.getService(ChatRoomService.class).sendMessage(message, false)
    .setCallback(new RequestCallback<Void>() {
        @Override
        public void onSuccess(Void param) { /* success */ }
        @Override
        public void onFailed(int code) { /* failure */ }
        @Override
        public void onException(Throwable exception) { /* error */ }
    });

// Observe incoming messages
Observer<List<ChatRoomMessage>> incomingChatRoomMsg = new Observer<List<ChatRoomMessage>>() {
    @Override
    public void onEvent(List<ChatRoomMessage> messages) {
        // Handle new messages
    }
};
NIMClient.getService(ChatRoomServiceObserver.class)
    .observeReceiveMessage(incomingChatRoomMsg, true);

Step 4: Leave Chatroom

NIMClient.getService(ChatRoomService.class).exitChatRoom(roomId);

4. UI Component Integration

Download the UI component demo from GitHub and import the uikit module into your project.

Key steps:

Configure repositories (e.g., maven { url "https://jitpack.io" }).

Add version variables in the root build.gradle (e.g., nimVersion = '8.4.6').

Include the uikit module in settings.gradle ( include ':uikit').

Add implementation project(':uikit') to the app module.

Initialize UI after the SDK in the Application class:

public class NimApplication extends Application {
    @Override
    public void onCreate() {
        SDKOptions sdkOptions = new SDKOptions();
        NIMClient.init(this, null, sdkOptions);
        if (NIMUtil.isMainProcess(this)) {
            NimUIKit.init(this);
        }
    }
}

Use ChatRoomMessageFragment in your activity or fragment to display the chatroom UI, then call:

NimUIKit.enterChatRoomSuccess(result, true);
if (messageFragment != null) {
    messageFragment.init(roomId);
}

To exit, call both SDK and UI methods:

NIMClient.getService(ChatRoomService.class).exitChatRoom(roomId);
NimUIKit.exitedChatRoom(roomId);

Summary

Following the steps above allows developers to integrate NetEase Cloud's chatroom solution into Android apps quickly, handling SDK setup, permissions, ProGuard configuration, message flow, and UI components, enabling high‑concurrency chat experiences with minimal effort.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

IntegrationAndroidNetEaseChatroom SDK
NetEase Smart Enterprise Tech+
Written by

NetEase Smart Enterprise Tech+

Get cutting-edge insights from NetEase's CTO, access the most valuable tech knowledge, and learn NetEase's latest best practices. NetEase Smart Enterprise Tech+ helps you grow from a thinker into a tech expert.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.