Skip to content

Android (Kotlin, Compose)

Native Android apps use the Kotlin core (dev.qualgent.quameleon.qa.core) and the Android platform layer (dev.qualgent.quameleon.qa.platform) directly. Neither depends on React Native or Compose; Compose support is picked up at run time when it is present. The platform sources reference OkHttp and AndroidX Fragment, so while you compile the SDK from source those two must be on the compile classpath (compileOnly); they stay optional at run time.

Until the Maven artifacts are published, compile the sources in a small Android library module. The paths below assume the Quameleon repository is checked out next to your project root; adjust them to where it lives.

quameleon/build.gradle.kts (a new Android library module)
plugins {
id("com.android.library")
// AGP 8.x only: also id("org.jetbrains.kotlin.android"). AGP 9 compiles Kotlin itself.
}
android {
namespace = "dev.qualgent.quameleon.qa"
compileSdk = 36
defaultConfig {
minSdk = 24
consumerProguardFiles("../../Quameleon/packages/qa-core/android/consumer-rules.pro")
}
// AGP 9: the accessor form sourceSets["main"].java.srcDir(...) fails with a ClassCastException
// (DefaultAndroidLibrarySourceSet ... cannot be cast to AndroidLibrarySourceSet); use the block form.
sourceSets {
getByName("main") { kotlin.directories.add("../../Quameleon/packages/qa-core/android/src/main/java") }
// AGP 8.x: getByName("main") { java.srcDir("../../Quameleon/packages/qa-core/android/src/main/java") }
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
dependencies {
// Referenced by the platform layer (OkHttp capture, Fragment screens); optional at run time.
compileOnly("com.squareup.okhttp3:okhttp:4.12.0")
compileOnly("androidx.fragment:fragment:1.8.9")
}
settings.gradle.kts
include(":quameleon")
app/build.gradle.kts
dependencies {
implementation(project(":quameleon"))
// and in every module that calls the SDK, for example the one that builds your OkHttpClient
}

consumer-rules.pro keeps the framework members the SDK reaches by reflection, so minified builds need no rules of their own. apps/qa-native-android is a complete example with Views, Compose, Fragments, OkHttp, HttpURLConnection, WebViews and push.

Optional modules:

  • Gradle plugin id("dev.qualgent.quameleon.qa") injects OkHttp and WebView capture into QA variants and adds a quameleonVerify<Variant> task that fails a store build containing the SDK (skip it if you ship production mode).
  • qa-ndk captures native (NDK) crashes. It is opt-in.
App.kt
import dev.qualgent.quameleon.qa.core.ProductionConfig
import dev.qualgent.quameleon.qa.platform.QuameleonAndroid
class App : Application() {
override fun onCreate() {
super.onCreate()
QuameleonAndroid.startProduction(
this,
ProductionConfig(
apiKey = BuildConfig.QUAMELEON_KEY,
endpoint = "https://quameleon.qualgent.ai",
dir = QuameleonAndroid.productionDir(this), // <filesDir>/quameleon_prod
publicKeyPem = BuildConfig.QUAMELEON_PUBLIC_KEY, // encrypts the spool and uploads
),
)
}
}

Keep the keys out of source control. One way is to read them from local.properties (gitignored) into BuildConfig:

app/build.gradle.kts
import java.util.Properties
android {
buildFeatures { buildConfig = true }
defaultConfig {
val local = Properties().apply {
rootProject.file("local.properties").takeIf { it.exists() }?.inputStream()?.use { load(it) }
}
// The PEM is multi-line: store it in local.properties with \n escapes and re-escape it for the Java literal.
fun quoted(v: String?) = "\"" + (v ?: "").replace("\\", "\\\\").replace("\n", "\\n").replace("\"", "\\\"") + "\""
buildConfigField("String", "QUAMELEON_KEY", quoted(local.getProperty("quameleon.apiKey")))
buildConfigField("String", "QUAMELEON_PUBLIC_KEY", quoted(local.getProperty("quameleon.publicKey")))
}
}

startProduction returns the cached remote config JSON, or null when production mode did not start (a QA run is already active, the config is invalid, or the remote kill switch is on). QA activation is off in release builds unless you turn it on (see QA runs); keep it explicitly off in store builds. The Gradle plugin’s quameleonQa { production.set(true) } forces this into every non-QA variant’s merged manifest:

AndroidManifest.xml (store flavor)
<meta-data android:name="dev.qualgent.quameleon.QA_ACTIVATION" android:value="false" />

Privacy-sensitive capture (network_bodies, push_content, console, screenshots, layout, shake) stays off in production until your code turns it on with QuameleonCore.configure(...) after startProduction; remote config can only turn it off. Session replay also needs your opt-in: pass replaySampleRate in ProductionConfig.

val client = QuameleonOkHttp.instrument(OkHttpClient()) // interceptor + EventListener (DNS, TLS, TTFB)
// or: OkHttpClient.Builder().addInterceptor(QuameleonOkHttp.interceptor())
// .eventListenerFactory(QuameleonOkHttp.eventListenerFactory()).build()

HttpURLConnection capture is opt-in with the network_huc config key. Query strings, headers and bodies are never captured unless you allowlist a URL pattern in network_bodies, and credentials are always removed.

Activities and Fragments become screen signals automatically (native_screens, on by default for native apps). A single-activity Compose app otherwise reports one screen (MainActivity), so register your NavController once and its destinations (label, else route) become screens:

val navController = rememberNavController()
remember(navController) { QuameleonScreens.trackNavController(navController) } // dev.qualgent.quameleon.qa.platform

Add your own:

QuameleonCore.screen("checkout", route = null)
QuameleonCore.emit("event", "order.placed", """{"items":{"t":"int","v":2}}""")
QuameleonCore.logException(e) // a handled error

From SDK 0.5, identify users and capture product events:

QuameleonCore.identify("user_8412", """{"plan":"pro"}""") // after sign-in; persisted across launches
QuameleonCore.capture("order.placed", """{"items":{"t":"int","v":2}}""")
QuameleonCore.reset() // on sign-out

See the Kotlin reference.

Compose is read through its semantics tree (what accessibility sees), so no Compose dependency is needed:

  • Modifier.testTag("checkout.place") becomes the tap target id, the hierarchy node id and the QA assertion handle.
  • Text and contentDescription become labels, unless the node is an input.
  • Password and editable text fields are always masked in replay and never labelled.
Button(onClick = ::placeOrder, modifier = Modifier.testTag("checkout.place")) { Text("Place order") }
// The test id of a View is its resource entry name (android:id="@+id/checkout_place"), else its contentDescription.
// Override the mapping with QuameleonAndroid.idResolver = { view -> ... } if you use another convention.
QuameleonAndroid.markSensitive(balanceView) // the view and its subtree are blacked out in replay

Password inputType fields are always masked, and every EditText is masked while mask_all_inputs is on (always on in production).

To let a test host drive QA builds, activate from the launch intent through QuameleonQaActivation:

if (QuameleonQaActivation.activate(activity, adapter = "native")) QuameleonAndroid.install(app, activity)

The launch extras alone never activate QA mode, because any app on the device can start your exported launcher activity with them. activate also requires:

  • a QA build: debuggable, or <meta-data android:name="dev.qualgent.quameleon.QA_ACTIVATION" android:value="true"/> (the Gradle plugin adds it to QA variants). Release builds without the flag stay dormant, and false always wins.
  • the host’s provisioning: before launching, the host writes adb shell settings put global quameleon_qa_token v1:<sha256(token)>:<expires>. Only adb shell can write Settings.Global; it holds a hash, so other apps reading it learn nothing. quameleon-qa and @quameleon/qa-host (android.launch) do this for you; a hand-rolled am start must do it too.

A hand-rolled launch (what android.launch and android.revokeToken do):

Terminal window
T=$(openssl rand -hex 16); EXP=$(( $(date +%s) + 3600 ))
adb shell settings put global quameleon_qa_token "v1:$(printf %s "$T" | shasum -a 256 | cut -d' ' -f1):$EXP"
adb shell am start -W -S -n <pkg>/<activity> --es quameleon_token "$T" --ei quameleon_port 47321 --el quameleon_token_expires "$EXP"
adb forward tcp:47321 tcp:47321 # connect + hello with $T, then:
adb shell settings delete global quameleon_qa_token # once connected, and again at the end of the run

Calling QuameleonCore.activate(...) directly, without QuameleonQaActivation, always refuses.

Then record with npx quameleon-qa record --android-serial <serial> --package <pkg> --out runs/1 --replay, or run scripted tests with npx quameleon-qa test qa-tests --android-serial <serial>. See CLI.

Scripted steps inject real touches into the top-most window under the target, so a Dialog, PopupWindow, bottom sheet or spinner dropdown above your activity gets them, and the hierarchy lists those windows first (flagged overlay). A second activity on top (such as expo-video’s fullscreen player) is read and tapped too: every resumed activity’s windows count, and the top one is the base. back in a Dialog sends it the BACK key (cancel). Targets match a dialog button’s text ignoring case, so Cancel finds a button drawn as “CANCEL”. A disabled view (setEnabled(false)) shows enabled: false; steps wait up to 2 s for it to become enabled before tapping.