Import and Initialize SDK

Last Updated on: 15 Mar, 2023

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 disagree with these terms, do not download, access, or use the SDK or the underlying services.

Ensure that all the executions are carried out on the main thread.

Add Meson SDK to the project

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

Gradle

Add the following to your app's build.gradle file inside the 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 Meson Prime SDK to your build.gradle dependencies:

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

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 Adapter

IMPORTANT

If you have InMobi setup as an S2S partner in the UI, there is no need to use the InMobi SDK.

In addition to integrating the Meson Prime SDK, publishers using Meson Mediation must follow the instructions below to integrate desired third-party networks' SDKs into their apps:

  1. Set up your app in the third-party network's dashboard and the Meson UI. For more information, see Network Guides.
  2. Download the relevant network's SDK. Select the checkbox of the relevant networks from the following table to find their SDKs.
  3. Add additional manifest modifications and dependencies for networks.

Gradle

 

 

 

Add Mandatory Dependencies

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

 

Add permissions to your Android manifest.

 

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

 

Manual

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

For more information on the supported networks and their setup guides, see Network Guides.

Facebook Audience Network
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
InMobi Audience Bidding
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
Vungle
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
Mintegral
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
Unity Predicted CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
Applovin Predicted CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK
Google Admob Fixed CPM     Banner, Interstitial, MREC, Rewarded, Native Adapter | SDK
Google Ad Manager
Fixed CPM     Banner, Interstitial, MREC, Rewarded, Native Adapter | SDK
AdColony Advanced Bidding Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | 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:18.0.1'

// 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"

Initialize the SDK

Use the MesonSdkConfiguration object to initialize the SDK. The listener object is optional.

MesonSdkConfiguration

Follow the instructions below to initialize the SDK:

  1. To initialize the SDK, call (Kotlin example) the MesonSdk.initialize(mesonSdkConfiguration, listener) method. You must initialize the SDK successfully before carrying out any other operations.

Kotlin

//GDPR settings from your CMP 
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 
} 

//Set your configuration with your APPID 
val mesonSdkConfiguration = MesonSdkConfiguration.Builder(this, "<MESON_APP_ID>").setConsent(gdprConsent).build()  

MesonSdk.initialize(mesonSdkConfiguration, object : MesonSdkInitializationListener { 
    override fun onComplete(error: Error?) { 
        if(error == null) { 
            //You can start to make ad requests 
        } else { 
            //Something is wrong 
        } 
    } 
})

Java

//GDPR settings from your CMP 
JSONObject pubConsent = new JSONObject(); 
try { 
    //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>"); 
} catch (JSONException e) { 
    e.printStackTrace(); 
}  

//Meson Configuration object 
MesonSdkConfiguration mesonSdkConfiguration = new MesonSdkConfiguration.Builder(getApplicationContext(), "<MESON_APP_ID>").setConsent(pubConsent).build();  

MesonSdk.Companion.initialize(mesonSdkConfiguration, new MesonSdkInitializationListener() { 
    @Override 
    public void onComplete(@Nullable Error error) { 
        if(error == null) { 
            //Initialization is successful, and you can make ad requests 
        } else { 
            //continue with publisher integration 
        } 
    } 
});
  1. To check the initialization status, you can call isSDKInitialized.

Kotlin

//Optionally you can check our api MesonSdk.isSDKInitialized()
if(MesonSdk.isSDKInitialized()) {
  //Initialised is true
} else {
  //Initialised is false
}

Java

//Optionally you can check our api MesonSdk.Companion.isSDKInitialized();
if(MesonSdk.Companion.isSDKInitialized()) {
  //Initialised is true
} else {
  //Initialised is false
}

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);