Skip to content

Latest commit

 

History

History
72 lines (61 loc) · 3.68 KB

GETTING_STARTED_XML_JAVA.md

File metadata and controls

72 lines (61 loc) · 3.68 KB

Getting started: XML / Java

DevConsole's public facade is a Kotlin object, but every method carries @JvmStatic and the async variants carry @JvmOverloads. From Java it reads like an ordinary utility class, and you never touch a coroutine: the ...Async variants take a callback instead.

  1. Add the JitPack repository, then apply the production-safety plugin and split the dependency by variant (same settings.gradle.kts / build.gradle.kts shape as the Kotlin guide — see GETTING_STARTED_XML_KOTLIN.md steps 1–2). The two coordinates are com.github.devconsole-android.DevConsole:devconsole for debug and com.github.devconsole-android.DevConsole:devconsole-noop for release; there is no BOM.

  2. 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. Add the optional launcher view to a debug-only layout:
<io.devconsole.ui.views.DevConsolePanelView
    android:id="@+id/dev_console_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  1. Initialize, and use the Async counterparts of startBrowser()/stop() since Java has no coroutines. The full debug runtime starts its foreground keep-alive service automatically when startBrowserAsync(...) succeeds. Pass it a callback and call panel.setEndpoint(...) from it if you want the panel to show the bound address once it's known (DevConsoleState.Running itself carries no payload, so this is the only way to get it):
DevConsole.initialize(getApplication(), DevConsoleConfig.builder()
    // 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.
    .openTriggers(OpenTriggers.builder().shakeToOpen(true).floatingButton(true).build())
    .build());

DevConsolePanelView panel = findViewById(R.id.dev_console_panel);
CoroutineScope panelScope = CoroutineScopeKt.CoroutineScope(Dispatchers.getMain());
panel.bind(
    DevConsole.state(),
    panelScope,
    () -> {
        DevConsole.startBrowserAsync(result -> {
            if (result instanceof StartResult.Started) {
                panel.setEndpoint(((StartResult.Started) result).getEndpoint());
            }
        });
        return Unit.INSTANCE;
    },
    () -> { DevConsole.stopAsync(StopReason.UserRequested.INSTANCE); return Unit.INSTANCE; }
);
  1. Push, mocks, network/socket capture, feature flags, and state providers all have plain Java-constructible types (PushInput, MockRule, NetworkRequestInput, FeatureFlag, DevConsoleConfig, ...) — none of them use Kotlin default arguments with @JvmOverloads, so every constructor parameter must be supplied explicitly from Java, and a StateProvider needs an anonymous-class implementation rather than a lambda (it isn't a Kotlin fun interface). See the full working example — network + WebSocket capture, mocks, a manually-built push event, a Firebase-shaped push event run through FirebaseRemoteMessageAdapter with no real Firebase dependency, a feature flag, and a state provider — in samples/views-java-app.

See PUSH.md, COMPOSER_AND_MOCKS.md, and STATE_AND_FLAGS.md for what those calls do.