Skip to main content
All CollectionsSwaarm MMPMMP: Developer DocumentationSDK
Android SDK: Step by Step Implementation guide
Android SDK: Step by Step Implementation guide
Updated over a week ago

The Swaarm Android SDK will allow you to track installs, events, re-engagements and much more in your Android app. Follow the steps below in this guide to set up your app to work with the Swaarm SDK. You can find the Swaarm Android SDK on Github.

โš ๏ธ Important:

The Swaarm Android SDK supports Android 4.4 (KitKat) and higher.

Step 1: Setting up your Environment

In order to start using the Swaarm Android SDK, it first needs to be added to your project.

  1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories as shown below:

    allprojects { 
    repositories {
    ...
    maven { url 'https://jitpack.io' }
    }
    }

  2. Add the dependency as shown below:

    dependencies {
    ...
    implementation 'com.github.swaarm:android-sdk:X.X.X' //pick the latest version. Same as tag name in Github
    }

Step 2: Add Google Play Services

For Apps in Google Play Store, Swaarm needs to identify Appset ID/vendor ID for attribution. In order to make this available in the Swaarm SDK, Google Play Services library for the same needs to be included in your project.

Add the dependency to the dependencies section of your build.gradle file as shown below:

dependencies { 
implementation 'com.google.android.gms:play-services-appset:16.0.2' //to get appSetId/vendorId
...
}

Step 3: Add Google Play Services for Advertising ID (Optional)

For Apps in Google Play Store, you can optionally include Google Advertising ID library for accurate attribution. If you decide to use Advertising ID in the Swaarm SDK, Google Play Services library for the same needs to be included in your project.

dependencies { 
...
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' //to get advertisingId (optional)
}

Step 4: Add Permissions

The Swaarm Android SDK needs the following permissions. You can add these to the AndroidManifest.xml file of your project as shown below in examples.

  1. Access Network State: This is needed to collect network related informations. For eg: if the device is connected/disconnected.

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

  2. Internet: This is needed for the Swaarm SDK to send data to the Swaarm Servers.

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

  3. Advertising ID: This is needed to read the Google Advertising Id for attribution. More information on this can be found here.

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

Step 5: Set up Proguard

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

-keep class com.swaarm.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();
}

Step 6: Configure SDK

The Swaarm Android SDK can be integrated and configured using the global Android Application class in your project by following the steps below:

  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 initialise the Swaarm SDK:

    import com.swaarm.sdk.SwaarmAnalytics; 
    import com.swaarm.sdk.SwaarmConfig;

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

    SwaarmConfig config = new SwaarmConfig(this, "https://organization.swaarm.com", "access-token")
    SwaarmAnalytics.configure(config)

    SwaarmAnalytics.configure(config, () -> { //called when configuration initialization completed //Check the logs for errors when unable to initialize });
    }
    }

๐Ÿ’กTip:

You can find the access token for the app in the Swaarm Dashboard

Step 7: Event tracking and Debugging using the Swaarm SDK

You need to set up event tracking so that the Swaarm SDK can pass event information to the Swaarm backend as shown in the example below:

SwaarmAnalytics.event("event_type_id", 123D, "custom value", 321D)


You can also setup the SDK to display additional logs and debug output by using the following command:

SwaarmAnalytics.debug(true)

Step 8: Build your App and Publish it

Congratulations, you are now ready to build, run and distribute your app. Swaarm SDK is all set to start tracking your events and attributing them!

Did this answer your question?