Back to top

Android SDK Integration

Last Updated on: 20 Jul, 2022

BEFORE YOU START

  • Meson supports Android version 4.4 (API Level 19) and above.
  • Supported Version of GAM: 21.0.0
  • For older versions, please refer to SDK Changelog.
  • The download, use, and access to the SDK are subject to the Meson SDK Licensing Terms. If you do not agree to the terms of Meson Publisher Online Terms & Conditions, do not download, access, or use the SDK or the underlying services.

Add the Meson SDK to your project

Meson supports both Gradle dependencies and manual download mechanisms to integrate our SDK.

Gradle

Add the following to your app's build.gradle file inside repositories section.

Add mavenCenteral repository to your app's build.gradle.

allprojects {
  repositories {
    mavenCentral()
    . . .
  }
}

On successful sync, you’ll be able to add any Android dependency hosted on mavenCentral repository to build.gradle.

Add the following to the dependencies section of build.gradle:

dependencies {
    implementation 'ai.meson.sdk:meson-wrap:2.0.3'
}

Manual

Download WRAP SDK 2.0.3

Copy the .AAR files to your application module’s libs/directory.

Add the following to your build.gradle file under the dependencies section.

implementation fileTree(dir: 'libs', include: ['*.aar'])

Add the Plugins for GAM

Gradle

To add GAM plugins with Gradle, enter the following in your build.gradle:

implementation 'ai.meson.sdk:meson-wrap-gam:2.0.3'

Manual

Download GAM Plugin 2.0.3

Import the .AAR file as a library project

Copy the .AAR file to your application module’s libs/directory.

Add the following to your build.gradle file under the dependencies section.

implementation fileTree(dir: 'libs', include: ['*.aar'])

Add Kotlin Dependencies

Add the Kotlin dependencies to your build.gradle, if you are NOT using Kotlin for development:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"
    implementation "androidx.core:core-ktx:1.3.2"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
}

Add Play Services Dependencies

Add the Play Services dependencies to your build.gradle, to allow GAID information to be retrieved.

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

Add ProGuard Rules

If you are using ProGuard, you must add the following code to your ProGuard file

  • If using Android Studio: proguard-rules.pro
  • If using Eclipse: proguard-project.txt
-keep class ai.meson.** {*;}
-keep interface ai.meson.** {*;}
-keepclassmembers class ai.meson.** { public *; }

Initialize the SDK

Initialize the SDK as follows:

Kotlin

/*Meson SDK Configuration Object*/
val gdprConsent = JSONObject().run {
      put(MesonWrap.MES_GDPR_CONSENT_AVAILABLE, true) //consent value that is obtained from User
      put(MesonWrap.MES_GDPR_CONSENT_GDPR_APPLIES, "0") //0 if GDPR is not applicable and 1 if applicable
      put(MesonWrap.MES_GDPR_CONSENT_IAB, "<IAB String v1 or v2>")//user consent in IAB format
}

val mesonSdkConfiguration = MesonSdkConfiguration.Builder(context, "<MESON_APP_ID>").setConsent(gdprConsent).build()

/*Initialize Wrap SDK*/  
MesonWrap.initialize(mesonSdkConfiguration, object: MesonSdkInitializationListener {
  override fun onComplete(error: Error?) {
    if(error == null) {
        //Integrate for GAM.
    } else {
        //continue with publisher integration
    }
  }
})

Java

/*Meson SDK Configuration Object*/
JSONObject pubConsent = new JSONObject();

//consent value that is obtained from User
pubConsent.put(MesonWrap.Companion.getMES_GDPR_CONSENT_AVAILABLE(), true);

//0 if GDPR is not applicable and 1 if applicable
pubConsent.put(MesonWrap.Companion.getMES_GDPR_CONSENT_GDPR_APPLIES(), "0");

//user consent in IAB format   
pubConsent.put(MesonWrap.Companion.getMES_GDPR_CONSENT_IAB(), "<IAB String v2 or v1>");

MesonSdkConfiguration mesonSdkConfiguration = new MesonSdkConfiguration.Builder(context, "<MESON_APP_ID>").setConsent(pubConsent).build();

/*Initialize Wrap SDK*/
MesonWrap.Companion.init(mesonSdkConfiguration, new MesonSdkInitializationListener() {
  @Override
  public void onComplete(@Nullable Error error) {
    if(error == null) {
        //Integrate for GAM.
    } else {
        //continue with publisher integration
    }
  }
});

Restricted Data Processing

To help publishers comply with the California Consumer Privacy Act (CCPA), the Meson SDK allows publishers to use either of the following parameters to enable restricted data processing (RDP). The parameter can be set at an ad request level utilizing the following parameters:

rdp: Set this to 1 for signaling restricted data processing.

us_privacy: Follow the IAB specification for signaling restricted data processing.

Kotlin

// You can notify Meson that restricted data processing is enabled using either of the following parameters.
val extras = JSONObject.run {    
    put("rdp", false)
    put("iab_usprivacy_string", "1YNN")
}
MesonSdk.setExtras(extras)

Java

// You can notify Meson that restricted data processing is enabled using either of the following parameters.
  JSONObject extras = new JSONObject();
  extras.put("rdp", false);
  extras.put("iab_usprivacy_string", "1YNN");
  MesonSdk.Companion.setExtras(extras);

Add User Data

This is optional. In case you want to send us any information about the user, please do as follows:

Kotlin

To set user data, follow:

//Set Extras
val ppidObject = JSONObject().run {
    put("PPID", "3f4364a6-cc98-4cbf-8b67-7aec972833ff")
}
val extras = JSONObject()
extras.run {
    put("age", 18)
    put("gender", BaseMesonInit.GENDER.MALE.value)
    put("segments", JSONArray(listOf("s1", "s2", "s3")))
    put("experiments", JSONArray(listOf("e1", "e2", "e3")))
    put("customIds", JSONArray(listOf(ppidObject)))
}
MesonSdk.setExtras(extras)


//Set Location
  val location = Location(LocationManager.GPS_PROVIDER);  
  location.latitude(12.935386622398175);  
  location.longitude(77.69424226118132);  
  location.accuracy(90);  
  location.time(System.currentTimeMillis());  
  MesonSdk.setLocation(location)

To get or reset user data, follow:

//Getters
  MesonSdk.getExtras() //gets the extra values set in SetExtras
  MesonSdk.getSDKVersion() //gets the SDK version

//Clears extras, location
  MesonSdk.cleanUserInfo()

Java

To get or reset user data, follow:

//Set Extras
  JSONObject extras = new JSONObject();
  extras.put("age", 18);
  extras.put("gender", BaseMesonInit.GENDER.MALE.getValue());
  extras.put("interests", "interests");
  extras.put("segments", new JSONArray(Arrays.asList("s1", "s2", "s3")));
  extras.put("experiments", new JSONArray(Arrays.asList("e1", "e2", "e3")));
  extras.put("customIds", new JSONArray());
  MesonSdk.Companion.setExtras(extras);
  MesonWrap.Companion.setPPID("adada134412y1876dad");
//Set Location
  Location location = new Location(LocationManager.GPS_PROVIDER);  
  location.setLatitude(12.935386622398175);  
  location.setLongitude(77.69424226118132);  
  location.setAccuracy(90);  
  location.setTime(System.currentTimeMillis());  
  MesonSdk.Companion.setLocation(location);

To get or reset user data, follow:

//Getters
MesonSdk.Companion.getExtras() //gets the extra values set in SetExtras
MesonSdk.Companion.getSDKVersion() //gets the SDK version

//Clears extras, location
MesonSdk.Companion.cleanUserInfo()

Configure Logging

When logging is set to DEBUG, SDK will print key logs to the console that provide useful information about the initialization and bid request lifecycle.

Kotlin

MesonWrap.setLogLevel(LogLevel.DEBUG)

Java

MesonWrap.Companion.setLogLevel(BaseMesonInit.LogLevel.DEBUG);

WHAT'S NEXT

Next, let's integrate Banner/Interstitial ad units.