Apps Kit SDK logoApps Kit SDK
文档 · AppsKitSDK (AKS) — Android 集成指南

1. 依赖项

1.1 AKS SDK

在应用级 build.gradle.kts 中添加 SDK 本身:

kotlin
dependencies {
    implementation("com.github.Pentabit-Labs-LLC:appskitsdk-android:${LATEST_VERSION}")
}

将 ${LATEST_VERSION} 替换为 appskitsdk-android 发布版本中的最新标签(也可查看该仓库 README 中的 JitPack 徽章),例如 v6.4.0.0。

AKS 以一组原始 .aar 文件的形式发布(并非包含依赖信息的 Maven 模块),因此它的所有第三方依赖都不会通过传递依赖自动引入。以下所有依赖都必须在应用模块中显式声明。唯一的例外是 SupportAKS(com.pentabit.aks_android_support_lib)——这些类已直接打包在 appskitsdk-android 构件中,因此无需单独添加 com.pentabit:aks-android-helpers。

1.2 必需的库(始终需要)

AKS 编译后的代码会直接引用这些库,因此无论实际启用了哪些广告平台,都必须添加:

kotlin
dependencies {
    // Firebase (Remote Config drives almost all AKS behavior; Analytics is used for AKS events)
    implementation(platform("com.google.firebase:firebase-bom:34.3.0"))
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-config")
    implementation("com.google.android.gms:play-services-measurement-api:23.0.0")

    // Coroutines / serialization / datetime — used throughout AdsManager and AppsKitSDK
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
    implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")

    // Ktor — AKS's internal network client for fetching ad/config data
    implementation("io.ktor:ktor-client-core:3.3.3")
    implementation("io.ktor:ktor-client-okhttp:3.3.3")
    implementation("io.ktor:ktor-client-content-negotiation:3.3.3")
    implementation("io.ktor:ktor-serialization-kotlinx-json:3.3.3")
    implementation("io.ktor:ktor-client-logging:3.3.3")

    // Local storage AKS uses for its own preferences/session/ad-state tracking
    implementation("com.russhwolf:multiplatform-settings:1.1.1")
    implementation("com.russhwolf:multiplatform-settings-serialization:1.1.1")

    // SQLDelight — backs AKS's own local analytics database (AksLocalDbManager). It's
    // referenced directly by AKS's compiled code, and — like every other dependency in this
    // guide — carries no dependency metadata on the JitPack AAR (bare .pom, no .module), so
    // omitting it doesn't fail the build, it crashes at runtime the first time
    // AppsKitSDK.initialize() runs: NoClassDefFoundError: app/cash/sqldelight/Transacter.
    implementation("app.cash.sqldelight:runtime:2.3.2")
    implementation("app.cash.sqldelight:android-driver:2.3.2")

    // Jetpack Compose — AKS's Feature/Cross-Promotion ad screens, the Configuration
    // Dashboard, and the Test Suite (§10) are all built with Compose. Pull these in via
    // the Compose BOM so versions stay aligned with whatever else in your app uses Compose.
    implementation(platform("androidx.compose:compose-bom:2025.08.01"))
    implementation("androidx.compose.runtime:runtime")
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.material3:material3")
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-tooling-preview")

    // Image loading used by AKS's built-in cross-promotion / feature-promotion ad screens
    implementation("io.coil-kt.coil3:coil:3.3.0")
    implementation("io.coil-kt.coil3:coil-compose:3.3.0")
    implementation("io.coil-kt.coil3:coil-compose-core:3.3.0")
    implementation("io.coil-kt.coil3:coil-network-ktor3:3.3.0")
    implementation("media.kamel:kamel-image:0.9.5")

    // Used by enableAppAutoUpdate() in the AKS base Activities
    implementation("com.google.android.play:app-update:2.1.0")
    // Powers AppsKitSDKUtils.askForRating() — AKS's built-in in-app review flow
    implementation("com.google.android.play:review:2.0.1")
    implementation("androidx.recyclerview:recyclerview:1.4.0")

    // IronSource core — AKS's base Activity classes call IronSource.onResume()/onPause()
    // unconditionally on every screen, so this is required even if you never select
    // IronSource as an ad network in the AKS portal.
    implementation("com.ironsource.sdk:mediationsdk:8.5.0")
}

所有 ktor-* 构件的 Ktor 版本必须保持一致——在同一类路径中混用 Ktor 2.x 和 3.x 构件会导致二进制不兼容,引发运行时崩溃。

应用其余部分使用的协程(1.7.3)、序列化(1.9.0)、Firebase BOM(34.3.0)和 SQLDelight(2.3.2)版本也必须与 AKS 保持一致,不要让依赖图中的其他位置仍保留旧版本。Firebase BOM 在不同主版本之间(33.x → 34.x)存在破坏性变更;即使 Gradle 静默解析并选定了某个“胜出”的版本,也无法保证 AKS 中调用这些库的代码路径仍然保持二进制兼容——这些是硬性要求,而非尽量遵循的建议。

1.3 移动监测合作伙伴(MMP)SDK(始终需要)

AKS 会根据 AKS 管理后台 / Firebase Remote Config 中设置的密钥自动初始化以下三个 SDK。你无需直接调用它们,但 AKS 编译后的代码会无条件引用这些 SDK 的类,因此它们必须位于类路径中:

kotlin
dependencies {
    // AppsFlyer
    implementation("com.appsflyer:af-android-sdk:6.13.0")
    implementation("com.appsflyer:adrevenue:6.9.0")
    implementation("com.miui.referrer:homereferrer:1.0.0.6")
    implementation("com.android.installreferrer:installreferrer:2.2")

    // Adjust
    implementation("com.adjust.sdk:adjust-android:4.38.3")

    // Solar Engine (Reyun)
    implementation("com.reyun.solar.engine.oversea:solar-engine-core:1.3.1.4")
}

如果 AKS 管理后台配置中没有某个 SDK 的密钥,也没关系——AKS 只会在运行时跳过它的初始化。但仍须添加该依赖,应用才能构建。

1.4 广告平台 / 广告聚合 SDK

除了 IronSource(已在上文列出),AKS 还在同一个 AAR 中打包了 AdMob、AppLovin MAX 和 Chartboost Mediation (Helium) 的处理代码。实际由哪个广告平台展示广告取决于远程配置(按广告形式配置,并支持故障转移),因此最稳妥的做法是将它们全部引入——Pentabit 自己的参考应用也采用了这种方式:

kotlin
dependencies {
    // ---- AdMob / Google Mobile Ads + mediation adapters ----
    implementation("com.google.android.gms:play-services-ads:24.4.0")
    implementation("com.google.ads.mediation:applovin:13.0.1.0")
    implementation("com.google.ads.mediation:ironsource:8.5.0.1")
    implementation("com.google.ads.mediation:chartboost:9.8.2.0")
    implementation("com.google.ads.mediation:vungle:7.4.2.0")
    implementation("com.google.ads.mediation:facebook:6.18.0.0")
    implementation("com.google.ads.mediation:mintegral:16.9.71.0")
    implementation("com.google.ads.mediation:pangle:6.4.0.4.0")
    implementation("com.google.ads.mediation:unity:4.12.5.0") {
        exclude(group = "com.google.android.gms", module = "play-services-cronet")
    }

    // ---- AppLovin MAX + adapters ----
    implementation("com.applovin:applovin-sdk:13.3.0")
    implementation("com.applovin.mediation:google-adapter:+")
    implementation("com.applovin.mediation:google-ad-manager-adapter:+")
    implementation("com.applovin.mediation:ironsource-adapter:8.7.0.0.0")
    implementation("com.applovin.mediation:facebook-adapter:+")
    implementation("com.applovin.mediation:vungle-adapter:+")
    implementation("com.applovin.mediation:mintegral-adapter:+")
    implementation("com.applovin.mediation:bytedance-adapter:6.5.0.8.1")
    implementation("com.applovin.mediation:unityads-adapter:+") {
        exclude(group = "com.google.android.gms", module = "play-services-cronet")
    }

    // ---- Chartboost Mediation (Helium) + adapters ----
    implementation("com.chartboost:chartboost-mediation-sdk:4.7.1")
    implementation("com.chartboost:chartboost-mediation-adapter-admob:4.22.3.0.4")
    implementation("com.chartboost:chartboost-mediation-adapter-applovin:4.12.0.0.0")
    implementation("com.chartboost:chartboost-mediation-adapter-ironsource:4.7.5.2.0.0")
    implementation("com.chartboost:chartboost-mediation-adapter-vungle:4.7.1.0.0")
    implementation("com.chartboost:chartboost-mediation-adapter-meta-audience-network:4.6.16.0.0")
    implementation("com.chartboost:chartboost-mediation-adapter-pangle:4.5.5.0.3.0")
}

如果你确定永远不会在 AKS 管理后台配置中启用某个广告平台(例如 Helium),可以删除对应的依赖代码块。但请注意,AKS 内部的 AdNetwork 故障转移逻辑可以针对每种广告形式,将请求路由至 ADMOB、GAM、MAX、IRON_SOURCE 或 HELIUM 中的任意一个,因此精简此列表会降低远程配置的灵活性。