Skip to content
Codeskop

Android initialization

Start the SDK once, when your app launches. Choose zero-code setup in the manifest or an explicit call in your Application class.

Get your ingest key

Create a project in the Codeskop dashboard and copy its public ingest key:

  • cs_live_pk_… for production builds
  • cs_test_pk_… for development and testing

Public keys can only send events, never read data, so they're safe to ship inside an APK.

Never use a secret key in an app

If the SDK is given a secret key (cs_…_sk_…) or anything that isn't a public Codeskop key, it refuses to start and captures nothing. It won't crash your app.

Option A: zero code (manifest)

Add your key to AndroidManifest.xml. The SDK starts itself through AndroidX App Startup before Application.onCreate runs, and does its setup off the main thread.

AndroidManifest.xml
<application ...>    <meta-data        android:name="codeskop.api_key"        android:value="cs_live_pk_YOUR_KEY" /></application>
OptionTypeDefaultDescription
codeskop.api_keystringNoneYour public ingest key. Required; without it, auto-init does nothing.
codeskop.endpointstringhttps://api.codeskop.comIngest URL. Only change this if Codeskop gives you a different one.
codeskop.capture_exception_messagesbooleanfalseSend exception messages instead of [REDACTED]. Added in 0.2.0.

Every other option keeps its default. For any other setting, use Option B.

Option B: explicit init (in code)

Call CodeskopAndroid.init from Application.onCreate. Use this when you need to choose settings at runtime or use a different key per build type.

MyApplication.kt
import android.app.Applicationimport com.codeskop.sdk.android.CodeskopAndroidimport com.codeskop.sdk.core.CodeskopConfig class MyApplication : Application() {    override fun onCreate() {        super.onCreate()        CodeskopAndroid.init(            this,            CodeskopConfig(apiKey = BuildConfig.CODESKOP_KEY),        )    }}

Keep keys out of source code

Inject the key through BuildConfig so debug builds report to your test project and release builds report to production:

app/build.gradle.kts
android {    buildFeatures {        buildConfig = true    }    buildTypes {        debug {            buildConfigField("String", "CODESKOP_KEY", "\"cs_test_pk_YOUR_TEST_KEY\"")        }        release {            buildConfigField("String", "CODESKOP_KEY", "\"cs_live_pk_YOUR_LIVE_KEY\"")        }    }}

Use one option, not both

If your manifest has a codeskop.api_key and you call CodeskopAndroid.init, the manifest wins, because App Startup runs first. The SDK only starts once; later calls are ignored.

What happens at startup

init returns immediately. On a background thread the SDK then:

  1. checks the key,
  2. reads basic device and app details (model, OS version, app version),
  3. fetches its remote config,
  4. installs crash and ANR capture,
  5. schedules background sync with WorkManager.

Nothing is captured until this finishes, which usually takes a moment. Every SDK method is safe to call at any time, even before init: early calls do nothing instead of throwing.

Letting users opt out

If a user has turned off analytics or diagnostics in your app, don't start the SDK for that session:

MyApplication.kt
class MyApplication : Application() {    override fun onCreate() {        super.onCreate()        if (userSettings.telemetryAllowed) {            CodeskopAndroid.init(this, CodeskopConfig(apiKey = BuildConfig.CODESKOP_KEY))        }    }}

To pause capture while the app is running (for example, right after the user changes the setting), call Codeskop.setEnabled(false). That setting only lasts for the current process. On the next launch, the check above decides whether the SDK starts.

Next steps