Skip to main content

Android SDK Integration

Before you start

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

Supported Version of GAM: 20.2.0

Supported Version of MoPub: 5.16.0

For older versions please refer to SDK Changelog.

The download, use and access to the SDK is 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 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:

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:1.0.0'
}

Add the Plugins for GAM or MoPub#

Select the mediation platform:

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

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

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:17.0.0'
}

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 and pass user consent, as follows :

/*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.init(mesonSdkConfiguration, object: MesonSdkInitializationListener {
override fun onComplete(error: Error?) {
if(error == null) {
//Integrate for Mopub or GAM.
} 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:

private fun setUserInfo() {
MesonWrap.setAge(30)
MesonWrap.setAgeGroup(AgeGroup.BETWEEN_30_AND_34)
MesonWrap.setAreaCode("<areaCode>")
MesonWrap.setEducation(Education.COLLEGE_OR_GRADUATE)
MesonWrap.setGender(Gender.MALE)
MesonWrap.setInterests("<interests>")
MesonWrap.setKeywords("<keywords>")
MesonWrap.setLanguage("<language>")
MesonWrap.setLocationWithCityStateCountry("<city>", "<state>", "<country>")
val location = Location(LocationManager.GPS_PROVIDER)
location.run {
latitude = 12.935386622398175
longitude = 77.69424226118132
accuracy = 90f
time = System.currentTimeMillis()
}
MesonWrap.setLocation(location)
MesonWrap.setPostalCode("<postalCode>")
MesonWrap.setYearOfBirth("<yearOfBirth>")
}
private fun clearUserInfo() {
MesonWrap.cleanUserInfo()
}

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.

MesonWrap.setLogLevel(LogLevel.DEBUG)
What Next?

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