Installation
Applying the Gradle plugin, authenticating to the package repository, and starting the Android SDK in your app.
Installation is a single Gradle plugin. The plugin adds the SDK dependency and applies bytecode instrumentation, so the only thing your app code does is start the SDK.
Quick start
Enter the collector URL, project and app key below and pick a tab (Kotlin · Java) to generate the initialization code from those values. Advanced options are behind the "Advanced options" toggle.
// Application.kt
import com.sophonz.sdk.core.Sophonz
import com.sophonz.sdk.core.SophonzOption
class Application : android.app.Application() {
override fun onCreate() {
super.onCreate()
val options = SophonzOption()
options.setDefault()
options.setCollectorURL("https://in.sophonz.ai")
options.setProject("sophonz")
options.setAppKey("sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz")
Sophonz.setup(options)
Sophonz.initialize(applicationContext, this)
}
}Requirements
| Item | Requirement |
|---|---|
| minSdk | 21 or higher |
| compileSdk | 34 or higher |
| Android Gradle Plugin | 8.0.2 or higher |
| Gradle | 8.0.2 or higher |
| Kotlin | 2.0.21 or higher |
| JVM target | 11 |
The compileSdk and AGP requirements are recorded in the AAR metadata. Falling short fails the build rather than producing a warning.
CAUTION — If minSdk is below 26
Core library desugaring must be enabled. You also need AGP 8.3.0 or higher and android.useFullClasspathForDexingTransform=true in gradle.properties. The plugin checks at configuration time and reports what is missing.
Repository access
Artifacts are published to GitHub Packages, which requires authentication even for public packages.
pluginManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/sophonz-labs/sophonz-android-sdk")
credentials {
username = providers.gradleProperty("gpr.user").orNull
password = providers.gradleProperty("gpr.key").orNull
}
}
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/sophonz-labs/sophonz-android-sdk")
credentials {
username = providers.gradleProperty("gpr.user").orNull
password = providers.gradleProperty("gpr.key").orNull
}
}
}
}Keep gpr.user and gpr.key in ~/.gradle/gradle.properties so they are never committed. A token with read:packages is enough.
NOTE — Why the repository is declared twice
pluginManagement resolves plugins only. The SDK artifact is resolved through the app module's own dependency repositories, so the same entry is needed under dependencyResolutionManagement.
Applying the plugin
Apply it to the app module. It is not a library-module plugin and only acts on a module that also applies com.android.application.
plugins {
id("com.android.application")
id("io.sophonz.gradle") version "<version>"
}
dependencies {
implementation("io.sophonz:sophonz-android-sdk:<version>")
}The implementation line can currently be omitted, because the plugin adds the matching SDK version to the classpath itself. That automatic behaviour (autoAddSophonzDependencies) is already marked for removal in the source, so declaring it explicitly is the safer form going forward.
CAUTION — Check the version
The SDK has no release tag yet. The project version in the repository is 1.0.0-SNAPSHOT, and the README and the example app quote different numbers. Take the version from what is actually published to GitHub Packages.
Starting the SDK
Start it in Application.onCreate().
import io.sophonz.android.sophonzsdk.Sophonz
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
Sophonz.start(this)
}
}Sophonz is an object. Sophonz.getInstance() still works but is marked for removal, so do not use it in new code.
Exporters and processors must be registered before start().
Sophonz.addSpanExporter(myExporter)
Sophonz.start(this)NOTE — Auto-start is not the default
There is a bytecode feature that injects the start call into Application.onCreate(), but it is off by default. Enable it with bytecodeInstrumentation { autoSdkInitializationEnabled.set(true) }. Without it, the Sophonz.start(this) call above is required.
applicationInitTimingEnabled is a separate setting that is on by default. It instruments the same onCreate to measure startup time; it does not start the SDK.
Setting the app key
The collector URL and app key live in sophonz-config.json. They are baked into the SDK at build time, not passed at runtime.
{
"sdk_config": {
"ingest": {
"service_key": "app-key-replace-me",
"service_namespace": "my-project"
}
}
}service_key can also come from the SOPHONZ_SERVICE_KEY environment variable; the file wins when both are present. The full set of options is in Configuration.
Permissions
INTERNET and ACCESS_NETWORK_STATE are declared in the SDK's own manifest and merge in automatically. There is no need to redeclare them.
Verifying
Run the app and look for the session in the dashboard. If nothing arrives, check Sophonz.isStarted() first — the most common cause is leaving out the start() call without having enabled auto-start.