Step-by-step guide to integrate the CometChat Jetpack Compose UI Kit into your Android app.
AI Integration Quick Reference
Field
Value
Package
com.cometchat:chat-uikit-compose
UI Layer
Jetpack Compose (Material 3)
Init
CometChatUIKit.init(context, UIKitSettings, callback) — must resolve before login()
Login
CometChatUIKit.login("UID", callback) — must resolve before rendering components
Order
init() → login() → render. Breaking this order = blank screen
Auth Key
Dev/testing only. Use Auth Token in production
Calling
Optional. Add com.cometchat:calls-sdk-android to enable voice/video
Min SDK
Android 9.0 (API 28)
This guide walks you through integrating the CometChat Jetpack Compose UI Kit into an Android app. All UI components are native Compose composables built with Material 3. By the end you’ll have a working chat UI.
Dashboard → Your App → Credentials (e.g. us, eu, in)
You also need:
Android Studio (Hedgehog or later recommended)
An Android emulator or physical device running Android 9.0 (API 28) or higher
Kotlin configured with Compose compiler plugin
Gradle plugin 8.0+ with Kotlin DSL
Auth Key is for development only. In production, generate Auth Tokens server-side via the REST API and use loginWithAuthToken(). Never ship Auth Keys in client code.
Create your MainActivity.kt with the CometChat initialization and login flow. Since Compose uses a declarative approach, we track the auth state and render UI conditionally:
MainActivity.kt
import android.os.Bundleimport android.util.Logimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.material3.CircularProgressIndicatorimport androidx.compose.material3.Textimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.setValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport com.cometchat.chat.core.CometChatimport com.cometchat.chat.exceptions.CometChatExceptionimport com.cometchat.chat.models.Userimport com.cometchat.uikit.core.CometChatUIKitimport com.cometchat.uikit.core.UIKitSettingsclass MainActivity : ComponentActivity() { private val TAG = "MainActivity" private val appID = "APP_ID" // Replace with your App ID private val region = "REGION" // Replace with your App Region private val authKey = "AUTH_KEY" // Replace with your Auth Key private var isReady by mutableStateOf(false) private var error by mutableStateOf<String?>(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() val uiKitSettings = UIKitSettings.UIKitSettingsBuilder() .setRegion(region) .setAppId(appID) .setAuthKey(authKey) .subscribePresenceForAllUsers() .build() CometChatUIKit.init(this, uiKitSettings, object : CometChat.CallbackListener<String?>() { override fun onSuccess(s: String?) { Log.d(TAG, "Initialization completed successfully") loginUser() } override fun onError(e: CometChatException?) { error = "Init failed: ${e?.message}" } }) setContent { when { error != null -> { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text(error ?: "Unknown error") } } !isReady -> { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { CircularProgressIndicator() } } else -> { ChatApp() } } } } private fun loginUser() { CometChatUIKit.login("cometchat-uid-1", object : CometChat.CallbackListener<User>() { override fun onSuccess(user: User) { Log.d(TAG, "Login successful: ${user.uid}") isReady = true } override fun onError(e: CometChatException) { error = "Login failed: ${e.message}" } }) }}
init() must resolve before you call login(). Calling login() before init completes will fail silently.