In this article, you will learn how to integrate and initialize the Nimbus SDK into your mobile application. It will also explain how to turn test mode ON, which will allow you to test the integration
Build Setup
Include the following maven repository configuration in your project root build.gradle file.
Gradle > 6.8 (settings.gradle.kts)
dependencyResolutionManagement {repositories {google()mavenCentral()// Add the following maven repository for access to the Nimbus SDKmaven("https://adsbynimbus-public.s3.amazonaws.com/android/sdks") {credentials { username ="*" }content {includeGroupByRegex(".*\\.adsbynimbus.*") } } }}
Other Gradle Versions (build.gradle.kts)
allprojects {repositories {google()mavenCentral()// Add the following maven repository for access to the Nimbus SDKmaven { url =uri("https://adsbynimbus-public.s3.amazonaws.com/android/sdks")credentials { username ="*" }content {includeGroup("com.adsbynimbus.openrtb")includeGroup("com.adsbynimbus.android")includeGroup("com.iab.omid.library.adsbynimbus") } } }}
In your application's build.gradle file, include the Nimbus SDK and required OkHttp extension and ensure compilation is set to target Java 8.
// app/build.gradleapply plugin: 'com.android.application'android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }// If using Kotlin kotlinOptions { jvmTarget =JavaVersion.VERSION_1_8 }}dependencies { implementation "com.adsbynimbus.android:nimbus:2.+" // Full Nimbus SDK with NimbusAdManager. Update version number to match
}
Initialize Nimbus SDK
lateinit var context:Contextlateinit var publisherKey:Stringlateinit var apiKey:StringNimbus.initialize(context, publisherKey, apiKey)
Set Test Mode
Test mode can be turned off or removed when ready to test in your production environment. Test mode is required if connecting to a development environment.
Nimbus.setTestMode(true);
If initializing with a dev key, test mode is required to see test ads. Test mode must be turned off before release to production
Quick Start: How to Show an Ad
The code block below can now be used to show a test ad.
val manager =NimbusAdManager()// Obtain the ViewGroup from your layout to attach the advar adView: ViewGroup=findViewById(R.id.ad_view)// Call showAd for non-blocking ads, an ad will attach to 'adView' on a successful request and return in the callbackmanager.showBlockingAd(NimbusRequest.forInterstitialAd("position"), activity, object : NimbusAdManager.Listener {overridefunonAdResponse(nimbusResponse: NimbusResponse) {TODO("Optional override to receive a callback when a successful bid is made") }overridefunonAdRendered(controller: AdController) {TODO("Ad successfully loaded, attach an event listener to listen to ad events") }overridefunonError(error: NimbusError) {TODO("Handle error") }})// Call showBlocking ad to show a blocking fullscreen admanager.showBlockingAd(NimbusRequest.forInterstitialAd("position"), activity, object : NimbusAdManager.Listener {overridefunonAdResponse(nimbusResponse: NimbusResponse) {TODO("Optional override to receive a callback when a successful bid is made") }overridefunonAdRendered(controller: AdController) {TODO("Ad successfully loaded, attach an event listener to listen to ad events")TODO("Call controller.stop() to hide the ad and controller.destroy() to remove it completely") }overridefunonError(error: NimbusError) {TODO("Handle error") }})
Proguard/R8
If you are using R8, all the necessary ProGuard rules are included and work out of the box. If you are using ProGuard or run into any build issues, see the ProGuard/R8 section in Troubleshooting.