-
Notifications
You must be signed in to change notification settings - Fork 608
Chat SDK Android: Firebase Configuration
The ChatSDK is even easier to set up on Android than it is on iOS as we don't have Cocoapods to deal with and due to less steps in the set up process. For this reason we can complete the set up in a single tutorial instead of the 3 required to get the iOS version up and running.
The Android ChatSDK comes ready to go straight from the box. Download a clone from the repository and then run in Android Studio and you can fully test all the functionality on our test ChatSDK accounts. This tutorial will be looking at how you can add the ChatSDK to a custom project.
The first stage of adding the ChatSDK to your project involves importing the project modules into your project.
- Open your existing project and save the unzipped ChatSDK in a known location
- Click
file->new->import module - Click on the far right button to browse your directories and navigate to where you have saved the ChatSDK project.
- Select the following modules to import:
country_picker,facebook,firebase_plugin,generatorandsdk. - You should be able to import them all at once, if you can't then repeat the process to import all the needed modules.
If you try to sync Gradle you will see that it can't due to some missing parameters. We need to add the SDK Versions to your project.
- Go to gradle.properties in the root of your project.
- Add the following code: (This allows the build versions to be set for the ChatSDK all at once)
MIN_SDK = 15
ANDROID_BUILD_SDK_VERSION = 21
ANDROID_BUILD_TOOLS_VERSION = 21.1.0
ANDROID_BUILD_TARGET_SDK_VERSION = 21
ANDROID_COMPILE_SDK_VERSION = 21
Finally you need to ensure that the following repositories have been added to your project's build.gradle file:
repositories {
mavenCentral()
jcenter()
}
and the dependencies contain the following:
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:3.0.0'
Note: It is worth checking the latest version for these. The ones displayed are the correct ones on time of writing and will depreciate when new versions are released.
Setting up Firebase for Android is similar to the set up required for iOS but with some notable differences.
- Go to the Firebase website and create an account if you don't already have one
- Create a new project on the dashboard
- Click on the project and then click database in the left hand menu
- Copy the URL from your browser, it should look something like:
https://yourappname.firebaseio.com/ - Modify the URL to be in the following format:
gs://yourappname.appspot.com - Navigate to the
BDefines.javafile in your project.sdk->java->com->braunster.chatsdk->network->BDefines - Add your modified URL instead of the
FirebaseStoragePathand the original URL as theServerUrl
It should look similar to this:
public static final String BRootPath = "testRoot/";
public static String ServerUrl = "https://your-firebase-name.firebaseio.com/" + BRootPath;
public static String FirebaseStoragePath = "gs://your-firebase-name.appspot.com";
Note: We recommend adding a trailing slash to the BRootPath and the ServerUrl as problems have sometimes occurred when this is left off.
Note: The root path allows you to split the database into different branches. The data and users in each branch will be completely separate from each other meaning you can change the root path for your testing and live versions.
Finally you need to create a JSON file for your app on Firebase
- Navigate to the Firebase website
- Click the cog icon and then click Project settings
- Click Add app
- Click the Android icon
- Add your App package ID
- The rest of the instructions are all already covered, finishing should download a Google Services JSON file
- Add this JSON file to your sdk file.
IMPORTANT: You need to go through this process twice. The second time you must add the below package name to allow Firebase to connect to your project: com.braunster.androidchatsdk.firebaseplugin
- Click the cog icon and then click Project settings
- Click Add app
- Click the Android icon
- Add the package:
com.braunster.androidchatsdk.firebaseplugin - Download the JSON file
- Add the JSON file to your
firebase_pluginfolder
The Android ChatSDK is now completely configured with Firebase
