Environment Setup

Steps to add CometChat to your application.

1. Add the CometChat.aar and CometChatUI.aar files to your project as libraries. To add the libraries to your android studio project, please follow the below steps.

To add CometChat to your project as libraries you can follow one of the below two options:

Using JCenter

  1. Add the below lines in Project level build.gradle file in repositories section:
maven{
    url 'https://dl.bintray.com/cometchat/CometChat'
}

For example:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
 }
}
allprojects {
    repositories {
        jcenter()

        maven{
            url 'https://dl.bintray.com/cometchat/CometChat'​
 }
    }

}


  1. Add the below lines in Module level build.gradle file in dependencies section:
compile 'com.inscripts:CometChat:6.8.10'
compile 'com.inscripts:CometChatUI:6.8.10'

For example:

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
 })
    testCompile 'junit:junit:4.12'
 compile 'com.inscripts:CometChat:6.8.10'
 compile 'com.inscripts:CometChatUI:6.8.10'
}

Please Note : If you just plan on using our SDK with the UI. Please import com.inscripts:CometChat:6.8.10 and ignore the com.inscripts:CometChatUI:6.8.10 dependency.

Downloading and adding the .aar files.

Download the Android SDK package from my.cometchat.com.

The package consists of three folders:

a. CometChat – This folder consists of the CometChat.aar file
b. CometChatUI – This folder consists of the CometChatUI.aar
c. CometChat UI source – This folder consists of an Android project that we have created using our SDK. You can use the source code to make the necessary modifications to the app. Generate a new CometChatUI.aar and import it in you project.

a. Create new module from File->New module
b. Select Import .JAR or .AAR package option
c. Select the .aar file to import
d. Go to File->Project Structure, select your project in the left pane, add the two libraries as module dependencies.

2. Add the following dependencies to the dependencies section of the build.gradle file of your app. Sync the project with gradle files.

    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'org.apache.httpcomponents:httpcore:4.3.2'
    compile 'org.apache.httpcomponents:httpmime:4.3.3'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'com.pnikosis:materialish-progress:1.5'
    compile 'com.splitwise:tokenautocomplete:1.3.3'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'org.jsoup:jsoup:1.8.1'
    testCompile 'junit:junit:4.12'

3. You need to enable the Multidex for your android application. To enable Multidex please add the following line to the defaultConfig element of the build.gradle file of your application. To know more about Multidex applications and why it is necessary,please click here.

    multiDexEnabled true

4. Also add the following lines to the android element of your build.gradle file.

    dexOptions {
    incremental true
    javaMaxHeapSize "2048M"
    }

    packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    }

5. The next step is to add the necessary permissions to the AndroidMainfest.xml. Please add the below mentioned permissions to your application’s AndroidManifest.xml file.


<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <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.WRITE_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />

Please Note: For devices running Android 6.0 (API level 23) or above , users need to grant the permission to the app when the app is running and not before installing the app. This needs to be handled by you within the app else it may result in the application crashing. For more information regarding the dynamic permissions in android, please visit the following link

  • Was this helpful?
  • Yes   No