Android integration
Getting started
ApexAd is split into a dependency-light core and optional format or capability modules. Add the smallest surface you need, initialize once, then let each ad object own its load, show and destroy lifecycle.
The `net.apexsdk` coordinates shown here are the signed release coordinates. They become downloadable after domain verification and the first Central deployment. Until then, use the source checkout and demo application.
Requirements
| Minimum Android | API 21 for core and standard format modules |
|---|---|
| Integrity module | API 23 or later |
| Compile SDK | 35 in the current source release |
| Java bytecode | Java 17 toolchain |
| License | Apache License 2.0 |
Install
Add Maven Central to dependency resolution, then select core plus the format modules used by the application.
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
dependencies {
implementation("net.apexsdk:apex-sdk-core:0.1.0")
implementation("net.apexsdk:apex-sdk-banner:0.1.0")
implementation("net.apexsdk:apex-sdk-interstitial:0.1.0")
implementation("net.apexsdk:apex-sdk-native:0.1.0")
}
Keep all Apex modules on the same version. Optional modules declare their required Apex module dependencies through Maven metadata.
Module map
| Artifact | Purpose | Notes |
|---|---|---|
apex-sdk-core | Initialization, OpenRTB, consent, tracking, cache and runtime contracts | Required |
apex-sdk-banner | Banner, MRECT and MRAID rendering | Optional |
apex-sdk-interstitial | Fullscreen display lifecycle | Optional |
apex-sdk-native | IAB Native 1.2 parsing and view binding | Optional |
apex-sdk-conversational | Sponsored suggestions for in-app assistant surfaces | Depends on Native |
apex-sdk-video | VAST video parsing, playback and reward callbacks | Optional |
apex-sdk-appopen | Foreground lifecycle ads and frequency caps | Optional |
apex-sdk-inappbidding | Bid token and price signal for mediation | Optional |
apex-sdk-wallet | Google Wallet action capability | Optional Google dependency |
apex-sdk-integrity | Play Integrity leases and request signing | API 23+ |
apex-sdk-measurement | OM SDK integration boundary | Partner activation required |
apex-adapter-admob | AdMob mediation adapter | Optional |
Initialize once
Initialize from Application.onCreate(). The application token identifies the registered publisher application. The endpoint override is useful for private OpenRTB integrations; production applications should use HTTPS.
class PublisherApplication : Application() {
override fun onCreate() {
super.onCreate()
val tcfString = getSharedPreferences("IABTCF", MODE_PRIVATE)
.getString("IABTCF_TCString", null)
val config = ApexAdsConfig.Builder("YOUR_APP_TOKEN")
.adServerUrl("https://your-openrtb-endpoint.example/auction")
.cacheTtlSeconds(300)
.gdprConsentString(tcfString)
.build()
ApexAds.init(this, config)
}
}
The publisher token identifies a registered app. Demand API keys, signing lease secrets, service-account credentials and private PGP keys stay server-side.
Load a first banner
Add the view to a publisher layout, then create the ad with a placement identifier configured on the server.
<com.apexads.sdk.banner.BannerAdView
android:id="@+id/apex_banner"
android:layout_width="320dp"
android:layout_height="50dp" />
lateinit var banner: BannerAd
banner = BannerAd.Builder("home-feed-banner")
.adSize(AdSize.BANNER_320x50)
.listener(object : BannerAdListener {
override fun onAdLoaded() = banner.show(binding.apexBanner)
override fun onAdFailed(error: AdError) = logNoFill(error)
})
.build()
banner.load()
Lifecycle contract
Ad objects move through deterministic states: idle, loading, loaded, displayed, expired or failed. Preload fullscreen formats before the transition where they may be shown. Destroy an ad or its rendering view when the owning Android lifecycle is permanently finished.
| Host event | Publisher action |
|---|---|
| Screen becomes eligible | Create the ad and call load(). |
| Listener reports loaded | Render banner/native immediately or hold fullscreen format until the intended transition. |
| Natural pause occurs | Check readiness, then call show(activity). |
| Screen is permanently destroyed | Call the format's destroy or view cleanup method. |
| Load fails or no-fills | Preserve the app experience; never block content waiting for an ad. |
Next steps
Continue with the format-specific examples, then review privacy and production activation requirements before connecting real inventory.