cometchat-android-v5-core
Foundational rules for CometChat Android UI Kit v5. Initialization, login, UIKitSettings builder, dependency setup, and anti-patterns. Read this first.
cometchat · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add cometchat/cometchat-skills --skill cometchat-android-v5-core技能说明
name: cometchat-android-v5-core description: "Foundational rules for CometChat Android UI Kit v5. Initialization, login, UIKitSettings builder, dependency setup, and anti-patterns. Read this first." license: "MIT" compatibility: "Android 7.0+; Java 8+; Kotlin 1.8+; com.cometchat:chat-uikit-android:5.x" metadata: author: "CometChat" version: "3.0.0" tags: "chat cometchat android core rules initialization login builder patterns"
Ground truth:
com.cometchat:chat-uikit-android:5.x(+chat-sdk-android:4.x,calls-sdk-android:5.x) —javapthe resolved AARs from the Gradle cache +docs/ui-kit/android. Official docs: https://www.cometchat.com/docs/ui-kit/android/overview · Docs MCP:claude mcp add --transport http cometchat-docs https://www.cometchat.com/docs/mcp(or fetch the URL directly without MCP). V5 is legacy/maintenance-only (V6 is current); verify symbols against the resolved AAR.
Companion skills:
cometchat-android-v5-componentsprovides the component catalog (what exists);cometchat-android-v5-placementcovers where to put chat in your app;cometchat-android-v5-themingcovers visual customization.
Purpose
This is the foundational skill for every CometChat Android UI Kit v5 integration. It teaches how CometChat works on Android — initialization, login, the UIKitSettings builder, Gradle dependency setup, manifest permissions, and the anti-patterns that silently break integrations.
Read this skill first, before any component or placement skill.
Use this skill when
- Setting up CometChat in a new Android project
- Initializing the SDK (
CometChatUIKit.init) - Logging in / logging out users
- Configuring
UIKitSettingsvia the builder - Adding Gradle dependencies
- Debugging init or login failures
- "How do I set up CometChat?"
- "CometChat isn't initializing"
Do not use this skill when
- Customizing component appearance → use
cometchat-android-v5-theming - Adding a specific feature (calls, reactions) → use
cometchat-android-v5-features - Writing custom message templates → use
cometchat-android-v5-customization - Diagnosing runtime crashes → use
cometchat-android-v5-troubleshooting
1. Gradle Dependencies
Add the CometChat UI Kit dependency to your app-level build.gradle:
dependencies {
implementation 'com.cometchat:chat-uikit-android:5.+'
}
The UI Kit transitively pulls in the CometChat Chat SDK. For voice/video calling, add the calling SDK separately:
dependencies {
implementation 'com.cometchat:chat-uikit-android:5.+'
implementation 'com.cometchat:calls-sdk-android:5.0.+' // optional — only for calls (V5 calls SDK = 5.x; matches cometchat-android-v5-calls)
}
Ensure your project-level build.gradle includes the CometChat Maven repository:
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://dl.cloudsmith.io/public/cometchat/cometchat/maven/" }
}
}
Min SDK: 24 (Android 7.0). Compile SDK: 34+. Java: 8+. Kotlin: 1.8+.
⚠️ Important: Always use the published Maven artifact (
com.cometchat:chat-uikit-android:5.+). Never useimplementation project(':chatuikit')or other local module references — those are only for CometChat's own internal development. The Chat SDK (com.cometchat:chat-sdk-android) is transitively included by the UI Kit, so you do not need to add it separately.
1a. AndroidX + Jetifier (REQUIRED — non-negotiable)
The CometChat Chat SDK transitively depends on the legacy com.android.support:support-compat library. Modern Android Studio projects (Arctic Fox+) default to androidx.core instead. Without Jetifier, Gradle sees the same classes (android.support.v4.os.ResultReceiver, etc.) declared in both libraries and fails the build with:
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules
core-1.16.0.aar -> core-1.16.0-runtime (androidx.core:core:1.16.0)
and support-compat-26.1.0.aar -> support-compat-26.1.0-runtime
(com.android.support:support-compat:26.1.0)
Add these two lines to gradle.properties at the project root before any UI Kit code is wired in:
android.useAndroidX=true
android.enableJetifier=true
Both are mandatory. Jetifier rewrites the legacy android.support.* references in the CometChat SDK's transitive deps to their androidx.* equivalents at build time, so the duplicate-class error doesn't happen.
A freshly-created Android Studio project usually has android.useAndroidX=true already (Arctic Fox+) but Jetifier is OFF by default since it's deprecated in newer SDK landscapes. The CometChat V5 SDK still needs it. If gradle.properties doesn't have either line, append both. If it has useAndroidX=true but no Jetifier line, add the Jetifier line. Idempotent.
2. Initialization
CometChat must be initialized exactly once before any UI component is used. Initialization is asynchronous and must complete fully before mounting any CometChat* view.
The UIKitSettingsBuilder
Java:
import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder()
.setAppId(APP_ID) // Required. String from the CometChat dashboard.
.setRegion(REGION) // Required. "us", "eu", "in", etc.
.setAuthKey(AUTH_KEY) // Required for dev mode. Omit in production.
.subscribePresenceForAllUsers() // Optional — enables online/offline indicators.
.build();
Kotlin:
import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit
import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings
val uiKitSettings = UIKitSettings.UIKitSettingsBuilder()
.setAppId(APP_ID)
.setRegion(REGION)
.setAuthKey(AUTH_KEY)
.subscribePresenceForAllUsers()
阅读完整来源 ↗