Back to top

Import and Initialize SDK

Last Updated on: 03 Aug, 2022

BEFORE YOU START

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

The download and use of the SDK are 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.

Gradle

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-beta14'

Manual

Download Meson Prime SDK

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 Mediated SDK and Adaptor

Gradle

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.

  • Audience Network
  • InMobi
  • Vungle
  • Mintegral
  • Unity
  • Applovin
  • Google AdMob
  • Google Ad Manager
Real-time CPM
implementation 'com.facebook.android:audience-network-sdk:6.7.0'
implementation 'ai.meson.sdk.mediation:facebook:6.7.0.0-beta3'

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'

// Additional constraints for Facebook Audience Network SDKs
implementation 'androidx.annotation:annotation:1.0.0'

Add permissions to your Android manifest.

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

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Real-time CPM
implementation 'com.inmobi.monetization:inmobi-ads:10.0.7'
implementation 'ai.meson.sdk.mediation:inmobi:10.0.7.0-beta1'

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'

// Additional dependencies for InMobi SDK
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'androidx.browser:browser:1.3.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

Add permissions to your Android manifest.

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

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Real-time CPM
implementation 'com.vungle:publisher-sdk-android:6.11.0'
implementation 'ai.meson.sdk.mediation:vungle:6.11.0.0-beta1'

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 permissions to your Android manifest.

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

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Real-time CPM
allprojects {
  repositories {
    mavenCentral()
    // Add Mintegral maven repo URL under allprojects
    maven {
      url 'https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea'
    }
    . . .
  }
}
implementation 'com.mbridge.msdk.oversea:mbbid:16.1.41'
implementation 'ai.meson.sdk.mediation:mintegral:16.1.41.0-beta1'
implementation 'com.mbridge.msdk.oversea:reward:16.1.41'
implementation 'com.mbridge.msdk.oversea:interstitialvideo:16.1.41'
implementation 'com.mbridge.msdk.oversea:mbbanner:16.1.41'
implementation 'com.mbridge.msdk.oversea:interstitial:16.1.41'

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 permissions to your Android manifest.

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

// Mintegral will need additional permissions
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Predicted CPM
implementation 'com.unity3d.ads:unity-ads:4.2.1'
implementation 'ai.meson.sdk.mediation:unity:4.2.1.0-beta2'

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 permissions to your Android manifest.

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

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Predicted CPM
implementation 'com.applovin:applovin-sdk:11.4.3'
implementation 'ai.meson.sdk.mediation:applovin:11.4.3.0-beta1'

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 permissions to your Android manifest.

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

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Fixed CPM
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'ai.meson.sdk.mediation:admob:21.0.0.0-beta1'

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'

// Additional constraints for Google SDKs
// For apps targeting Android 12, add WorkManager dependency.
constraints {
  implementation('androidx.work:work-runtime:2.7.0')
}

Add permissions to your Android manifest.

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

// Admob and Ad Manager will need this in the manifest or the app will crash
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />   
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Fixed CPM
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'ai.meson.sdk.mediation:gam: 21.0.0.0-beta1'

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'

// Additional constraints for Google SDKs
// For apps targeting Android 12, add WorkManager dependency.
constraints {
  implementation('androidx.work:work-runtime:2.7.0')
}

Add permissions to your Android manifest.

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

// Admob and Ad Manager will need this in the manifest or the app will crash
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

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

Manual

Download the mediation adapters. Copy the .AAR files to the application module's libs/directory.

Download the mediated SDK. Copy the .JAR or .AAR files to the application module's libs/directory.

See the list of supported networks and integration guides here.

Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Predicted CPM
Adaptor | SDK
Predicted CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK

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

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

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'

// Additional constraints for Google SDKs
// For apps targeting Android 12, add WorkManager dependency.
constraints {
  implementation('androidx.work:work-runtime:2.7.0')
}

Add permissions to your Android manifest.

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

// Admob and Ad Manager will need this in the manifest or the app will crash
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

These permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience

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

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

NOTE

  • If you are using ProGuard and do not do this step you could have issues with initialization.
  • Please check proguard rules with networks you are using as these will also need to be added within.

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
  • Set the 'Do Not Sell' data restrictions within a US privacy jurisdiction (such as CCPA)
  • Initialize mediated SDKs

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

Kotlin

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

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

Java

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

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

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

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

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

/*Initialize Meson SDK*/  
MesonSdk.Companion.initialize(mesonSdkConfiguration, new MesonSdkInitializationListener() {
  @Override
  public void onComplete(@Nullable Error error) {
    if(error == null) {
    } 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

NOTE

  • To use cohorts in Meson UI, this is where you will need to set PPID unique to a user.
  • To use segments or experiments in Meson UI, this is where you will need to send the segments or experiments.

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 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())
}
// Set PPID
MesonSdk.setPPID("adada134412y1876dad")
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 set 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());
  // Set PPID
  MesonSdk.setPPID("adada134412y1876dad");
  MesonSdk.Companion.setExtras(extras);

//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 DDMS console that provide useful information about the initialization and bid request lifecycle.

Kotlin

MesonSdk.setLogLevel(LogLevel.DEBUG)

Java

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