Android SDK - Basic Integration

Video Guide Available

Watch this video for a detailed walkthrough of the integration process. Use both the video and the written guide below for best results.


Prerequisites

Complete the steps in Integrating a Singular SDK: Planning and Prerequisites before proceeding with this integration.

Important: These prerequisite steps are required for any Singular SDK integration.


Installation

Installation Methods

Note: Android Studio now defaults to Kotlin DSL (build.gradle.kts) for new projects. All code examples below show both Kotlin DSL (Recommended) and Groovy DSL formats.

Method 1: Gradle (Recommended)

Method 1: Gradle (Recommended)

Add SDK Repository

Configure the Singular Maven repository in your project's dependency management.

Note: Starting with Gradle 7, Android recommends using centralized repository declarations in settings.gradle or settings.gradle.kts over project or module level build.gradle declarations.

Gradle 7+ Configuration

Add the Singular SDK repository to your settings file:

settings.gradle.kts (Kotlin DSL - Recommended) settings.gradle (Groovy DSL)
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://maven.singular.net/")
        }
    }
}

Older Gradle Versions

For older Gradle versions, add the repository to your project-level build file:

build.gradle.kts (Kotlin DSL - Recommended) build.gradle (Groovy DSL)
repositories {
    mavenCentral()
    maven {
        url = uri("https://maven.singular.net/")
    }
}

Add Singular Library Dependency

Add the Singular library to your app module's dependencies.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
dependencies {
    implementation("com.singular.sdk:singular_sdk:12.13.0")
}

Troubleshooting: Duplicate Class Issues

You may encounter duplicate class errors when multiple dependencies include the same library. This commonly occurs with Google Play Services libraries when using older versions.

Common Error Example:

Duplicate class com.google.android.gms.common.api.ResultCallback found in modules play-services-6.5.87.aar and play-services-basement-17.6.0.aar

Resolution: Exclude Conflicting Dependencies

To resolve duplicate class issues, exclude the conflicting transitive dependency from the Singular SDK or other dependencies causing the conflict.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
dependencies {
    // Exclude specific Google Play Services modules from Singular SDK
    implementation("com.singular.sdk:singular_sdk:12.13.0") {
        exclude(group = "com.google.android.gms", module = "play-services")
    }

    // Add the specific Google Play Services libraries your app needs
    implementation("com.google.android.gms:play-services-ads-identifier:17.0.0")
    implementation("com.google.android.gms:play-services-appset:16.0.2")
}

Global Exclusion Rules

If the duplicate class conflict affects multiple dependencies across your project, you can apply a global exclusion rule.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
configurations.all {
    exclude(group = "com.google.android.gms", module = "play-services")
}

Verifying Dependency Resolution

After applying exclusion rules, verify your dependency tree to ensure conflicts are resolved.

Terminal Command
./gradlew app:dependencies --configuration debugRuntimeClasspath

This command displays the complete dependency tree for your app, showing which libraries are included and which have been excluded.


Samsung Galaxy Store Support

Add the Samsung Galaxy Store install referrer dependency if your app is distributed through Samsung Galaxy Store.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
dependencies {
    implementation("store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0")
}

Transitive Dependencies

If you have disabled transitive dependencies for the Singular SDK, manually add these required libraries to your app module's dependencies.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
dependencies {
    implementation("com.android.installreferrer:installreferrer:2.2")
    implementation("com.google.android.gms:play-services-appset:16.0.2")
}

Google Play Services Dependency

If your app doesn't implement Google Play Services API 17.0.0 or higher, add the following dependency.

app/build.gradle.kts (Kotlin DSL - Recommended) app/build.gradle (Groovy DSL)
dependencies {
    implementation("com.google.android.gms:play-services-ads-identifier:17.0.0")
}
Method 2: Manual Installation

Alternative Installation Methods

Manual Download

Download and manually integrate the SDK AAR file into your project.

  1. Download the SDK: Download the SDK from the link at the top of this page
  2. Extract and add to libs: Unzip the SDK package and add Singular.aar into your Android project's libs directory
  3. Create libs directory: If it doesn't exist, create a directory called libs in your project folder (usually at <project>/app/libs )
Method 3: Maven Installation

Maven Installation

Add the Singular Maven repository to your project's pom.xml file.

pom.xml
<project ...>
    <repositories>
        <repository>
            <id>singular.net</id>
            <url>http://maven.singular.net/</url>
        </repository>
    </repositories>
</project>

Add the dependency:

pom.xml
<dependency>
    <groupId>com.singular.sdk</groupId>
    <artifactId>singular_sdk</artifactId>
    <version>12.13.0</version>
</dependency>
Method 4: Eclipse Installation

Eclipse Installation

Integrate the SDK using Eclipse by following these steps.

You can use the Eclipse AAR plugin: gradle-eclipse-aar-plugin

If you don't want to use the plugin, follow these steps:

  1. Unzip the AAR: Unzip singular_sdk-12.13.0.aar
  2. Rename JAR file: Rename classes.jar to singular_sdk-12.13.0.jar (this is the main SDK jar)
  3. Add install referrer: Add the com.android.installreferrer:installreferrer:2.2 library to your project
  4. Copy permissions: Copy the BIND_GET_INSTALL_REFERRER_SERVICE permission from the AndroidManifest.xml contained in the AAR to your AndroidManifest.xml
  5. Copy license permission: Copy the CHECK_LICENSE permission from the AndroidManifest.xml contained in the AAR to your AndroidManifest.xml

ProGuard Configuration

ProGuard Rules

Add the following rules to your proguard.config file to prevent code obfuscation issues.

proguard.config
-keep class com.singular.sdk.** { *; }
-keep public class com.android.installreferrer.** { *; }
# Uncomment this line in case your are calling the 'revenue' function using the Google billing library
#-keep public class com.android.billingclient.** { *; }

Required Permissions

AndroidManifest Configuration

Add these permissions under the <manifest> tag in your AndroidManifest.xml file.

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="BIND_GET_INSTALL_REFERRER_SERVICE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

Exclude the com.google.android.gms.permission.AD_ID permission if you're integrating the Kids SDK .


Samsung Galaxy Store Queries

To support Samsung Galaxy Store's install referrer, add the following to your AndroidManifest.xml .

AndroidManifest.xml
<queries>
    <package android:name="com.sec.android.app.samsungapps" />
</queries>

SDK Integration

Privacy Compliance: Remain compliant with privacy laws enacted in regions where you do business, including GDPR, CCPA, and COPPA, when implementing the Singular SDKs. See SDK Opt-In and Opt-Out Practices for guidance.

Import Singular SDK

Add Import Statement

Import the Singular library in your MainActivity file.

Kotlin Java
import com.singular.sdk.*

Initialize the SDK

Create Initialization Function

To enable session tracking and attribution, initialize the Singular SDK each time your app launches by creating a private method and calling it from your MainActivity's onCreate() method.

Follow these steps:

  1. Add the Function: Place the initialization method inside your MainActivity class (or any entry-point Activity)
  2. Insert Credentials: Replace SDK KEY and SDK SECRET with your Singular SDK key and secret from your dashboard
  3. Update SingularConfig: Before initializing the SDK, create a SingularConfig object and set any SDK preferences (see Configuration Options below)
  4. Call the Function: Invoke initSingularSDK() in onCreate() after UI setup but before logging events

Basic Implementation

Create the initialization method with basic configuration.

Kotlin Java
private fun initSingularSDK() {
    // Configure Singular with SDK key and secret
    val config = SingularConfig("SDK KEY", "SDK SECRET")

    try {
        Singular.init(applicationContext, config)
        Log.d("Singular", "SDK initialized successfully")
    } catch (e: Exception) {
        Log.e("Singular", "SDK initialization failed: ${e.message}")
    }
}

Call from MainActivity onCreate

Invoke the initialization method in your MainActivity's onCreate() method.

Kotlin Java
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Initialize Singular SDK
    initSingularSDK()

    // Proceed with your app setup (e.g., UI initialization)
}

Implementation Guidelines

Follow these key guidelines when implementing the SDK initialization.

  • Placement: Add the initialization method in your MainActivity, not the Application class, to ensure proper session tracking
  • Error Handling: The try-catch block logs initialization errors (e.g., invalid credentials) without crashing your app
  • Deep Linking: To handle deep links (URLs that launch your app), see Supporting Deep Links for extended setup
  • META Install Referrer: Add config.withFacebookAppId("FacebookAppID") to enable Meta Install Referrer attribution

As of June 18th, 2025 , Meta's Advanced Mobile Measurement Reporting (AMM) removes the need for implementing Meta Install Referrer. It is not recommended to implement Meta Install Referrer if AMM reporting is enabled.

Pro Tip: If your app supports multiple entry points (e.g., deep links), ensure initSingularSDK() is called in each relevant Activity's onCreate() to guarantee consistent behavior.


Configuration Options

SingularConfig Methods

The SingularConfig object allows you to customize SDK behavior using chainable configuration methods. Refer to the table below for all available options.

Method Description
.withFacebookAppId(String facebookAppID) Configure the Facebook App ID. Required for Meta Install Referrer attribution . See Where can I find an app's Facebook App ID?

As of June 18th, 2025 , Meta's Advanced Mobile Measurement Reporting (AMM) removes the need for implementing Meta Install Referrer. It is not recommended to implement Meta Install Referrer if AMM reporting is enabled.

.withCustomUserId(String customId) Send the user ID to Singular
.withSingularLink(Intent intent, SingularLinkHandler handler)
.withSingularLink(Intent intent, SingularLinkHandler handler, long shortlinkTimeoutSec)
Enable deep linking with Singular Links. The single-argument overload uses a 10-second short link resolution timeout by default; use the three-argument overload to override it. This call also handles deferred deep links, so a separate withDDLHandler / withDDLTimeoutInSec configuration is no longer required.
.withOpenURI(URI openURI) Fetch the URI from the intent (to process deep links if the app is opened through a link that doesn't originate from Singular)
.withGlobalProperty(String key, String value, boolean overrideExisting) Set a global property to a given value. The key and value will be sent to Singular with any event/session sent from the app
.withSessionTimeoutInSec(long timeout) Set the session timeout
.withFCMDeviceToken(String token) Sets the FCM token to be sent on the first session
.withLoggingEnabled() Enable logging
.withLogLevel(int level) Configure the logging level (default is Log.ERROR)