Initialize the SDK

A step-by-step guide to initializing the SDK and setting up basic configurations in your Android app.

This guide walks you through initializing the Blueshift Android SDK and configuring basic settings.

👍

Prerequisite

Before you initialize the Blueshift SDK, your Android app must be registered in Firebase.

  • Add your Android app in the Firebase console.
  • Download the google-services.json file.
  • Place the file in your project’s app/ directory in Android Studio.

For detailed steps, see the Firebase setup guide.


1. Add the Google Services Gradle plugin

To link your Firebase configuration (google-services.json) with your Android app, you must add the Google Services Gradle plugin in both the project-level and app-level Gradle files.

Project-level build.gradle

Open your project-level build.gradle file (the one outside app/). Inside the plugins {} block, add:

// Groovy (build.gradle - project-level)
plugins {
    id 'com.google.gms.google-services' version '4.4.2' apply false
}
// Kotlin DSL (build.gradle.kts - project-level)
plugins {
    id("com.google.gms.google-services") version "4.4.2" apply false
}

App-level build.gradle

At the bottom of your app-level file, apply the plugin:

// Groovy (build.gradle - app-level)
apply plugin: 'com.google.gms.google-services'
// Kotlin DSL (build.gradle.kts - app-level)
apply(plugin = "com.google.gms.google-services")

2. Initialize the SDK

Initialize the Blueshift SDK in your app’s custom Application class within the onCreate() method.
This ensures that push notifications are delivered even when the app is not running in the foreground.

Create an Application class

Create a custom Application class to initialize the SDK.

// Java
package com.example.blueshiftsdktest;

import android.app.Application;
import com.blueshift.Blueshift;
import com.blueshift.model.Configuration;
import com.blueshift.BlueshiftLogger;

public class MyApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();

    // Enable logging for debugging
    BlueshiftLogger.setLogLevel(BlueshiftLogger.VERBOSE);

    Configuration configuration = new Configuration();
    configuration.setAppIcon(R.mipmap.ic_launcher);
    configuration.setApiKey("BLUESHIFT_EVENT_API_KEY");

    Blueshift.getInstance(this).initialize(configuration);
  }
}
// Kotlin
package com.example.blueshiftsdktest

import android.app.Application
import com.blueshift.Blueshift
import com.blueshift.model.Configuration
import com.blueshift.BlueshiftLogger

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Enable logging for debugging
        BlueshiftLogger.setLogLevel(BlueshiftLogger.VERBOSE)

        val configuration = Configuration()
        configuration.setAppIcon(R.mipmap.ic_launcher)
        configuration.setApiKey("BLUESHIFT_EVENT_API_KEY")

        Blueshift.getInstance(this).initialize(configuration)
    }
}
📘

Note:

You must set the Event API key here. Without it, the SDK integration will fail.
Find your Event API key in Account Settings > API Keys (from the top-right profile menu).

Register the class in your manifest

Open app/src/main/AndroidManifest.xml and add the android:name attribute inside the <application> tag:

<application
    android:name=".MyApplication"
    ... >
</application>
💡

Note:

Most Android projects already include a launcher activity by default.
You only need to ensure your Application class is registered and initialized as shown above.