Skip to content

Latest commit

 

History

History
141 lines (116 loc) · 6 KB

GETTING_STARTED_COMPOSE.md

File metadata and controls

141 lines (116 loc) · 6 KB

Getting started: Compose

About five minutes, most of it waiting for Gradle. By the end you'll have the inspector opening on your device and the dashboard reachable from a browser.

  1. Add the JitPack repository to settings.gradle.kts — that is where the library artifacts live (the Gradle plugin comes from the Gradle Plugin Portal and needs nothing extra).
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}
  1. Apply the production-safety plugin and split the dependency by variant.
plugins {
    id("io.github.devconsole-android")
}

dependencies {
    debugImplementation("com.github.devconsole-android.DevConsole:devconsole:<version>")
    releaseImplementation("com.github.devconsole-android.DevConsole:devconsole-noop:<version>")
    debugImplementation("com.github.devconsole-android.DevConsole:devconsole-ui-compose:<version>") // optional, only for the launcher panel
}

devConsole {
    enabledVariants.set(setOf("debug"))
    protectedVariantPatterns.set(listOf("(?i).*release"))
}

<version> is a JitPack version — 1.4.1 for the current release. Releases are tagged v1.4.1, and JitPack resolves a bare version against the v-prefixed tag, so the v is optional; the bare form is used here because it also matches the plugin's version on the Gradle Plugin Portal.

There is no BOM. devconsole (the debug runtime) and devconsole-noop are the only two coordinates a normal integration names; everything else is devconsole-<module>.

devconsole-ui-compose should be debugImplementation, never plain implementation. It has no release no-op counterpart and merges DevConsoleActivity into your manifest. The Gradle plugin now treats it as a protected coordinate and marker: a protected variant that includes it fails with a message directing you to use debugImplementation.

  1. Add INTERNET to your own app's manifest. The full debug runtime auto-merges ACCESS_LOCAL_NETWORK, NEARBY_WIFI_DEVICES, ACCESS_NETWORK_STATE, and the default foreground-service permissions; it does not merge INTERNET — without it, the embedded server fails with an opaque socket error instead of a clear permission message:
<uses-permission android:name="android.permission.INTERNET" />
  1. On a debuggable build you can skip explicit initialize entirely — the SDK auto-initializes, so state/timeline/capture are ready without any Application.onCreate boilerplate. The browser server itself is never auto-started; call DevConsole.startBrowser() yourself (step 5). Once it starts, the full debug runtime automatically starts its foreground keep-alive service. Read the connect URL from the returned StartResult.Started.access (or the device's More screen). The default URL is open; initialize explicitly with BrowserSecurity.SESSION_CODE when a shared LAN needs the single-use credential flow, or when you need other configuration (state providers, flags, open triggers):
DevConsole.initialize(
    application,
    DevConsoleConfig.default()
        // Optional: let the SDK open the in-app inspector on a shake or from a floating
        // button. Both are off by default and never start the server.
        .withOpenTriggers(OpenTriggers(shakeToOpen = true, floatingButton = true)),
)
  1. Drop in the optional Compose launcher panel, or build your own with DevConsole.state(). DevConsoleState.Running carries no payload, so capture the endpoint from onStart's own StartResult and pass it to the panel if you want the running address displayed:
setContent {
    val state by DevConsole.state().collectAsState()
    val scope = rememberCoroutineScope()
    var endpoint by remember { mutableStateOf<BrowserEndpoint?>(null) }
    MaterialTheme {
        DevConsolePanel(
            state = state,
            onStart = {
                scope.launch {
                    val result = DevConsole.startBrowser()
                    endpoint = (result as? StartResult.Started)?.endpoint
                }
            },
            onStop = {
                scope.launch {
                    DevConsole.stop(StopReason.UserRequested)
                    endpoint = null
                }
            },
            endpoint = endpoint,
        )
    }
}
  1. Tap Start. The panel shows the bound address, something like DevConsole server is running at 192.168.0.15:8080. Open that address in the default open mode, or use the connect URL from StartResult.Started.access.connectUrl when SESSION_CODE is enabled. If the device isn't local, run adb forward tcp:8080 tcp:8080 first — 8080 is only the first port tried, so use whatever port the panel actually shows.

Forwarding Timber / Log calls

Add devconsole-logs-timber to hand your existing log calls to the Logs inspector. The module is release-safe, so it can stay on implementation in every variant — in protected builds it forwards to DevConsole's disabled recorder:

implementation("com.github.devconsole-android.DevConsole:devconsole-logs-timber:1.4.1")

// Once, after DevConsole.initialize:
Timber.plant(DevConsoleTimberTree(DevConsole.logRecorder()))
DevConsoleLog.install(DevConsole.logRecorder())

// Existing call sites keep working and now also land on the timeline:
Timber.i("Checkout reached the timeline")
DevConsoleLog.w("Checkout", "Payment retried")

Use DevConsoleTimberTree(recorder, minimumPriority) to drop lines below a given android.util.Log priority.

For a full working example, samples/compose-app has one button per capability: network and WebSocket capture, mocks, push simulation, a feature flag, and a state provider.

For how each piece works, see NETWORK_INSPECTOR.md, WEBSOCKET_INSPECTOR.md, COMPOSER_AND_MOCKS.md, PUSH.md, and STATE_AND_FLAGS.md.