Integration

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 SDK
        maven("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 SDK
        maven {
            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.gradle
apply 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: Context
lateinit var publisherKey: String
lateinit var apiKey: String
Nimbus.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 ad
var 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 callback
manager.showBlockingAd(NimbusRequest.forInterstitialAd("position"), activity, object : NimbusAdManager.Listener {

    override fun onAdResponse(nimbusResponse: NimbusResponse) {
        TODO("Optional override to receive a callback when a successful bid is made")
    }

    override fun onAdRendered(controller: AdController) {
        TODO("Ad successfully loaded, attach an event listener to listen to ad events")
    }

    override fun onError(error: NimbusError) {
        TODO("Handle error")
    }
})

// Call showBlocking ad to show a blocking fullscreen ad
manager.showBlockingAd(NimbusRequest.forInterstitialAd("position"), activity, object : NimbusAdManager.Listener {

    override fun onAdResponse(nimbusResponse: NimbusResponse) {
        TODO("Optional override to receive a callback when a successful bid is made")
    }

    override fun onAdRendered(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")
    }

    override fun onError(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.

Last updated