Import and Initialize SDK

Last Updated on: 21 Mar, 2024

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 project-level 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-beta35'

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.
  • InMobi SDK update required: Integrations on or prior to version 10.1.4 necessitate removing the old dependency and adding the new one with the updated artifact ID “inmobi-ads-kotlin”. See the code snippet for InMobi Audience Bidding for the exact changes.

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

 

 

 

If you are on the Amazon network, see Integrate Amazon SDK for more information.

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

Exercise caution when accessing the manual SDK link, as it may include recent releases without compatibility and functionality testing. Utilizing the versions specified against each SDK is advisable, ensuring compatibility and reliable functionality.

  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 6.13.7
InMobi Audience Bidding
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 10.6.7
Vungle
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 6.12.1
Mintegral
Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 16.4.11
Unity Predicted CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 4.6.1
Applovin Predicted CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 11.11.3
Google Admob Fixed CPM     Banner, Interstitial, MREC, Rewarded, Native Adapter | SDK 21.5.0
Google Ad Manager
Fixed CPM     Banner, Interstitial, MREC, Rewarded, Native Adapter | SDK 21.5.0
AdColony Advanced Bidding Real-time CPM     Banner, Interstitial, MREC, Rewarded Adapter | SDK 4.8.0
Amazon Publisher Services Real-time CPM     Banner, Interstitial, Rewarded Adapter | SDK 9.7.0

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"

Add ProGuard Rules

This section is applicable only if you are using Android Gradle plugin 8.0 and above along with R8’s non-compat mode while pro guarding.

If your app’s build.gradle has set “minifiyEnabled” equal to “true” and uses R8's non-compat mode, which means that full-mode is enabled, make sure to include the relevant ProGuard rules, if the third-party network library you use has direct or transitive dependencies on the libraries Gson, Retrofit, and Infer Annotation, as it is applicable. For more information , see R8 FAQs.

gson:

-keepclassmembers,allowobfuscation class * {
 @com.google.gson.annotations.SerializedName;
}
-keepclassmembers class MyDataClass {
 !transient;
}
-keepattributes Signature
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken

retrofit:

-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>

Facebook infer-annotation:

-dontwarn com.facebook.infer.annotation.Nullsafe$Mode
-dontwarn com.facebook.infer.annotation.Nullsafe

Initialize the SDK

Deprecated API

  • MesonSdkConfiguration.Builder.setConsent(consent: JSONObject?) - This will be removed in a future version.
  • MesonSdkConfiguration.Builder.setBuildType(buildType: BaseMesonInit.MesonBuildType) - This will be removed in a future version.

Initialize

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 the initialize method from MesonSdkClass. You must initialize the SDK successfully before carrying out any other operations.

Kotlin

//Set your configuration with your application context and APP ID.
val mesonSdkConfiguration = MesonSdkConfiguration.Builder(this, "<MESON_APP_ID>").build()  

//Init SDK
MesonSdk.initialize(mesonSdkConfiguration, object : MesonSdkInitializationListener { 
    override fun onComplete(error: Error?) { 
        if(error == null) { 
            //Init Success, Ad Integrations may start here.
        } else { 
            //Init Failed, Please check the Error Message.
        } 
    } 
})

Java

//Set your configuration with your application context and APP ID. 
MesonSdkConfiguration mesonSdkConfiguration = new MesonSdkConfiguration.Builder(this, "<MESON_APP_ID>").build();  

//Init SDK
MesonSdk.Companion.initialize(mesonSdkConfiguration, new MesonSdkInitializationListener() { 
    @Override 
    public void onComplete(@Nullable Error error) { 
        if(error == null) { 
            //Init Success, Ad Integrations may start here.
        } else { 
            //Init Failed, Please check the Error Message.
        } 
    } 
});
  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);