Get started with Android SDK
Updated over a week ago

At a glance: Cost Center's Android SDK enables you to track attribution in your Android app. Follow the steps in this guide to set up your app to work with CC's SDK.

Step 1: Set up your environment

To start using CC's SDK, you will need to add it to your project as a dependency.

IMPORTANT

The minimum supported Android API level for CC's SDK integration is 9 (Gingerbread).

The Android SDK is available as an AAR archive. You can download it from our releases page.


Step 2: Add Google Play Services

Apps in the Google Play Store need to use the Google Advertising ID to identify devices. To enable the Google Advertising ID for our SDK, you need to integrate Google Play Services. To do this, add the Google Play Services library to your project. Add the following dependency to the dependencies section of your build.gradle file.

dependencies { implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' }

Note:
Cost Center's SDK is not tied to any version of the play-services-analytics dependency. You can use the any version of the Google Play Services library.


Step 3: Add permissions

Note:
Cost Center's SDK includes the com.google.android.gms.AD_ID permission by default. If your app targets children, you should remove the AD_ID permission to prevent Cost Center's SDK from reading it.

You can remove it by adding a remove directive if need to make your app COPPA-compliant

<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

Cost Center's SDK requires the following permissions. Add them to your AndroidManifest.xml file if they are not already present:

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 4: Set up Proguard

If you are using Proguard in your application, add the following lines to your Proguard file:

-keep class com.costcenter.sdk.** { *; } 
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}

-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }

Step 5: Set up install referrer

The install referrer is a unique identifier that you can use to attribute an app install to a source. Cost Center's SDK requires this information to perform attribution. You need to setup Google Play Referrer API so that Cost Center could gather this information:

Make sure you have the following in your build.gradle file:

dependencies { 
implementation 'com.android.installreferrer:installreferrer:2.2'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
}

If you are using Proguard, make sure you have added the following setting in your Proguard file:

-keep public class com.android.installreferrer.** { *; }

Step 6: Integrate the SDK into your app

We recommend using a global Android Application class to initialize Cost Center's SDK. If you do not have this set up, follow these steps:

  1. Create a class that extends the Application.

  2. Open the AndroidManifest.xml file and locate the <application> element.

  3. Add the android:name attribute and set it to the name of your application class. For example, if your Application class is named GlobalApplication:

    <application android:name=".GlobalApplication" <!-- ... --> </application>

  4. In your Application class, find or add the onCreate method. Add the following code to initialize the Cost Center's SDK:

    import android.app.Application
    import com.costcenter.sdk.CostCenterSDK

    public class GlobalApplication extends Application {
    @Override public void onCreate() {
    super.onCreate();
    CostCenterSDK.initialize(this);
    }
    }
Did this answer your question?