Skip to main content

Import and Initialize SDK

Before you start

Meson supports Android version 4.4 (API Level 19) and above.

The download and use of the SDK is subject to the Meson SDK Licensing Terms. If you do not agree to these terms, do not download, access, or use the SDK, or the underlying services.

Add Meson SDK to the project#

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

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

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:

implementation 'ai.meson.sdk:meson:1.0.0-beta1'

Add Mediated SDK and Adaptor#

To add the mediated SDK adaptor and SDK with Gradle, select the networks and add the following dependencies to the build.gradle.

See the list of supported networks and integration guides here.

Facebook Audience Network
Real-time CPM
InMobi
Real-time CPM
Vungle
Real-time CPM
MIntegral
Real-time CPM
Unity
Predicted CPM
AppLovin
Predicted CPM
IronSource
Fixed CPM
Google AdMob
Fixed CPM
Google Ad Manager
Fixed CPM

Add Additional Dependencies#

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

implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'

Add Kotlin Dependencies#

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

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 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 by calling Meson.initialize(mesonSdkConfiguration, listener) method. The SDK must be initialized successfully before carrying out any other operations.

During initialization, the SDK will:

  • Fetch the mobile app configurations from the server
  • Set the GDPR consent settings for the given app
  • Initialize mediated SDKs

Initialize the SDK once per app lifecycle using the MesonSdkConfiguration object. The listener object is optional.

/*Meson SDK Configuration Object*/
val gdprConsent = JSONObject().run {
put(Meson.MES_GDPR_CONSENT_AVAILABLE, true) //consent value that is obtained from User
put(Meson.MES_GDPR_CONSENT_GDPR_APPLIES, "0") //0 if GDPR is not applicable and 1 if applicable
put(Meson.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 Meson SDK*/
Meson.initialize(mesonSdkConfiguration, object: MesonSdkInitializationListener {
override fun onComplete(error: Error?) {
if(error == null) {
} else {
//continue with publisher integration
}
}
})

Add User Data#

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

To set user data, follow:

//Set Extras
Meson.setExtras({
"age":age,
"gender":Gender.MALE,
"interests":"interests",
"language":"language",
"customIds": [{"idType":"PPID", value: "adada134412y1876dad"},
{"idType":"IDL", value: "mpqdan134412y1876dad"}],
"segments": ["s1","s2","s3"],
"experiments": ["e1","e2","e3"]
})
//Set Location
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(12.935386622398175);
location.setLongitude(77.69424226118132);
location.setAccuracy(90);
location.setTime(System.currentTimeMillis());
Meson.setLocation(location)

To get or reset user data, follow:

//Getters
Meson.getExtras() //gets the extra values set in SetExtras
Meson.getSDKVersion() //gets the SDK version
//Clears extras, location
Meson.clearUserInfo()

Configure Logging#

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

Meson.setLogLevel(LogLevel.DEBUG)