Migrating Google's A2UI Compose Renderer to Kotlin Multiplatform
DEV Community

Migrating Google's A2UI Compose Renderer to Kotlin Multiplatform

Chatting with the A2UI Team and Volunteering for the Port

I spent nearly an hour chatting with Nick and Anton from the A2UI Compose team at Android Dev Summit 2026.

The month before, they had released 1.0.0-alpha02 of their Agent-to-UI renderer for Jetpack Compose (A2UI), but the official androidx.a2ui:* and androidx.compose.material3:material3-a2ui artifacts only target Android. Answering audience questions at the event, they mentioned several times that KMP / CMP support isn't a near-term priority. I noticed at least two or three other developers walk up to ask about KMP as well.

Since I had already written a deep dive on Google A2UI in my minibook GenUI Field Notes, I volunteered on the spot to handle the port and open-source it.

Instead of writing a third-party implementation from scratch, I built a migration pipeline directly on top of the official A2UI sources, ported them to Kotlin Multiplatform, and open-sourced a2ui-kmp.

On Android, Gradle Module Metadata redirects consumers straight to Google's official artifacts, so you run their unmodified code. On Desktop (JVM) and iOS, it compiles those same AOSP sources against a thin compatibility layer while keeping the original androidx.a2ui.* package names and APIs intact.

The booking form above runs the exact same A2UI message stream handling and outbound event logic in commonMain across macOS Desktop and the iOS Simulator.

Scoping out the codebase showed that the platform gaps came down to fewer than ten categories, and two-thirds of the upstream source files didn't need a single edit. That let me focus on the architecture and engineering boundaries:

  • Splitting packages cleanly so scripts manage synced upstream files while AI-written compatibility code lives in its own module;
  • Sharing a single dependency version catalog across subprojects, and wiring the Kotlin 2.3 and 2.4 builds together with includeBuild in a Composite Build so the repo works out of the box in the IDE;
  • Verifying the multiplatform compatibility layer against ground-truth output recorded from the official Jetpack Compose release.

First, let's look at how to add the library to your project. Then I'll walk through the architectural trade-offs.

Quick Start

Adding a2ui-kmp to a KMP project starts with one key version constraint. The official Jetpack Compose release of A2UI depends on the latest Compose alpha and compiles with Kotlin 2.4. Gradle upgrades Compose and kotlin-stdlib in the host app to the minimum versions required by its dependencies, but an older Kotlin compiler cannot read an iOS klib produced by a newer compiler. Because the klib ABI isn't backward-compatible, we split the modules into two tiers:

  • The 5 core packages (a2ui-model, a2ui-engine, compose-runtime, compose-ui, compose-ui-testing) are built with Kotlin 2.3.21 and Compose Multiplatform 1.12.2 (Compose runtime 1.12.1). Because none of them require Kotlin 2.4, iOS apps on Kotlin 2.3 or newer can use them right away.
  • material3-a2ui is built with Kotlin 2.4.0 and Compose Multiplatform 1.13.0-beta01, because upstream uses Material 3 APIs that only landed in CMP 1.13 (more on why in the Build Architecture section below). We'll move it to stable CMP 1.13 once that ships.

On Android, dependencies resolve directly to Google's official 1.0.0-alpha02 artifacts and inherit the upstream requirements: compileSdk 37 when using a2ui-model / a2ui-engine alone; compileSdk 37.1 and Jetpack Compose 1.13.0-alpha03 for compose-runtime and above; and Material 3 1.5.0-alpha28 when using material3-a2ui.

With those versions in place, add the modules you need to gradle/libs.versions.toml. We recommend adding a -kmp suffix to the catalog aliases to distinguish them from Google's Android-only coordinates:

# gradle/libs.versions.toml
[versions]
a2ui = "1.0.0-alpha02"
[libraries]
a2ui-material3-kmp = { module = "ai.littlepress.a2ui:material3-a2ui", version.ref = "a2ui" }
a2ui-compose-ui-kmp = { module = "ai.littlepress.a2ui:compose-ui", version.ref = "a2ui" }

The 6 published KMP artifacts map 1:1 to Google's official Android artifacts:

ai.littlepress.a2ui:* Artifact Purpose Android Resolution Target
a2ui-model Core data layer for app and component developers androidx.a2ui:a2ui-model
a2ui-engine Message and data-binding engine for renderer authors (no Compose dependency) androidx.a2ui:a2ui-engine
compose-runtime Compose A2UI renderer runtime (state and data binding) androidx.a2ui.compose:compose-runtime
compose-ui Compose A2UI renderer and catalog API (without Material 3) androidx.a2ui.compose:compose-ui
compose-ui-testing Testing APIs for custom catalog components androidx.a2ui.compose:compose-ui-testing
material3-a2ui Basic component catalog built on Compose Material 3 androidx.compose.material3:material3-a2ui

Most projects only need a2ui-material3-kmp (to use the Material 3 Basic Catalog out of the box) or a2ui-compose-ui-kmp (to build a custom component catalog), without worrying about the other four modules.

The snippet below, taken from samples/composeApp/src/commonMain/kotlin/sample/material3/A2ui.kt and FormSample.kt, shows how to initialize A2uiMessageProcessor, feed it agent messages, and collect user interaction events in commonMain. Since the sample agent doesn't send images, video, or audio, those three callbacks are no-ops; a real app plugs in its own image loader and media players there:

import ai.littlepress.a2ui.compat.android.content.Context
import androidx.a2ui.compose.runtime.A2uiMessageParser
import androidx.a2ui.compose.ui.A2uiMessageProcessor
import androidx.a2ui.compose.ui.catalog.A2uiBasicCatalogV1
import androidx.a2ui.model.processor.A2uiMessageProcessor
import androidx.a2ui.model.processor.processInput
import androidx.compose.foundation.layout.Arrangement
...

@Composable fun rememberA2uiProcessor(): A2uiMessageProcessor {
  val processor = remember {
    val catalog = materialA2uiBasicCatalogV1(
      // The sample's agent sends no images, video or audio, so these three
      // slots are empty; a real app plugs its image loader and players in here.
      image = MaterialA2uiBasicCatalogV1Defaults.image { _, _, _, _, _ -> },
      video = MaterialA2uiBasicCatalogV1Defaults.video { _, _, _ -> },
      audioPlayer = MaterialA2uiBasicCatalogV1Defaults.audioPlayer { _, _, _, _ -> },
      functions = A2uiBasicCatalogV1.Functions(Context()), // ①
    )
    A2uiMessageProcessor(catalogs = listOf(catalog))
  }
  LaunchedEffect(processor) {
    withContext(Dispatchers.Default) {
      processor.collectMessages()
    }
  }
  return processor
}

@Composable fun A2uiSurfaces(processor: A2uiMessageProcessor, modifier: Modifier = Modifier) {
  val surfaces by processor.activeSurfaces.collectAsState()
  Column(modifier, verticalArrangement = Arrangement.spacedBy(16.dp)) {
    surfaces.forEach { surface ->
      key(surface.id) {
        A2uiSurface(surface)
      }
    }
  }
}

@Composable fun FormScreen(incomingJsonLines: List<String>, onSendToAgent: (String) -> Unit) {
  val processor = rememberA2uiProcessor()
  LaunchedEffect(processor) {
    val parser = A2uiMessageParser()
    incomingJsonLines.forEach { json ->
      processor.processInput(parser, json)
    }
    processor.outboundEvents.collect { message ->
      onSendToAgent(message.toString())
    }
  }
  A2uiSurfaces(processor)
}

Here, rememberA2uiProcessor() creates a message processor wired to the Material 3 Basic Catalog and continuously consumes its message queue on a background coroutine. FormScreen feeds incoming JSON lines from the agent into processor and collects form submission events from outboundEvents.

If you look closely at the imports, you'll notice two A2uiMessageProcessor symbols: one is the top-level factory function in compose.ui, and the other is the interface in model.processor, which is how upstream designed it.

Calling A2UI from commonMain differs from Android code in just two small spots:

  • Two upstream public interface methods take java.util.Locale in their signatures; in commonMain, they use ai.littlepress.a2ui.compat.java.util.Locale instead (a typealias to java.util.Locale on JVM and Android).
  • At ①, A2uiBasicCatalogV1.Functions(context) takes an android.content.Context on Android, whereas on Desktop and iOS you pass ai.littlepress.a2ui.compat.android.content.Context() (which delegates to the host OS browser to open URLs).

Source Migration Architecture

Keeping Google's original package names and public APIs intact means handling the JDK and Android types they depend on underneath. Across the 193 .kt files in the 6 upstream modules, the Compose UI rendering code barely touches Android-specific APIs, but references to java.util.Locale, SimpleDateFormat, NumberFormat, ICU MessageFormat, android.util.JsonReader, android.content.res.Resources, and ReentrantLock are scattered throughout the codebase.

Before writing the code, design review and our early iterations helped us avoid two traps:

  1. Platform APIs and Compatibility Layer

    Could we keep the java.* package names as-is? We considered declaring package java.util in iosMain for a custom Locale so we wouldn't even have to touch upstream imports. That falls apart in a multiplatform setup. Because two upstream public interfaces expose java.util.Locale in their method signatures, the type has to live in commonMain. On the JVM, the classloader rejects any user-defined java.* package at load time (SecurityException: Prohibited package name) and collides with the JDK's built-in classes. Putting all shims under ai.littlepress.a2ui.compat.* and rewriting imports by rule solved both problems cleanly.

  2. Upstream Sync and Directory Layering

    The second question was how to sync upstream code and structure the repo so upstream snapshots and our own code stay separate. We didn't need to mirror AOSP's internal build workflow. Pulling the latest release head directly from the AOSP git repository, including its tests and resource directories, was enough. Separating the upstream and downstream directories let us enforce a strict rule: scripts handle all upstream syncing and mechanical rewrites, while multiplatform compatibility code lives in its own module, written with AI assistance and verified through review and testing.

    The repository is structured around that split:

    a2ui-kmp/
    ├── source/# read-only upstream snapshot
    │ ├── UPSTREAM # the AOSP commit it came from
    │ ├── a2ui/
    │ └── material3-a2ui/
    ├── target/
    │ ├── build-logic/ # source + overlays -> commonMain
    │ ├── a2ui-kmp/# Kotlin 2.3 build: 5 core packages
    │ │ ├── a2ui-compat/ # hand-written compatibility layer
    │ │ ├── a2ui-model/
    │ │ │ ├── overlay-generated/# rule-based rewrites
    │ │ │ └── overlay-generated.json# rules + sha256
    │ │ ├── a2ui-engine/
    │ │ └── compose/
    │ └── material3-a2ui-kmp/# Kotlin 2.4 build: material3-a2ui
    │ ├── overlay-generated/
    │ ├── overlay-manual/# hand-written (one file today)
    │ └── resources-generated/# generated translations
    ├── tests/integration/ # tests against published artifacts
    ├── samples/
    └── scripts/ # sync, rewrite, verify, record
    
  3. Overlay Replacement and Change Verification

    The files compiled into commonMain fall into five layers, each maintained in only one way:

    • source/ (read-only AOSP snapshot, managed by sync-upstream.py): Pulls source/a2ui/ and source/material3-a2ui/ at the AOSP commit pinned in source/UPSTREAM for androidx.a2ui 1.0.0-alpha02, verified file-by-file in CI by check-upstream.py. Out of 193 upstream .kt files, 124 compile as-is without a single line changed.
    • target/*/overlay-generated/ (rule-based rewrites, managed by generate-overlays.py): Of the remaining 69 files that touch platform APIs, 68 only need deterministic mechanical rewrites, mostly repointing java.* / android.* imports to ai.littlepress.a2ui.compat.* and replacing Locale.US constants and ::class.java.simpleName. Each module's overlay-generated.json records the applied rule names and the upstream file's sha256, and DEVELOPMENT.md lists the full rule table.
    • target/*/overlay-manual/ (hand-maintained replacements, verified by overlay-manual.json): If a file needs even a one-line logic change beyond the fixed rewrite rules, it isn't allowed in overlay-generated/ and must go into overlay-manual/. Across all 193 source files in the repo, only one file sits here today: ShimmerIndicator.kt. On Android, the original implementation mutates the same shader's localMatrix every animation frame; on Desktop and iOS, Skia shaders are immutable once created, so we recreate the RadialGradientShader each frame with the current offset and radius.
    • target/a2ui-kmp/a2ui-compat/ and each module's own src/ (compatibility layer, maintained separately): Implements Locale, ICU MessageFormat, CLDR 45 plural rules, date/number/currency formatting, a strict JsonReader, and a FIFO-fair ReentrantLock on iOS. Everything here lives under ai.littlepress.a2ui.compat.* without touching upstream directories.
    • resources-generated/ and recorded reference fixtures (generated or recorded by script, never edited by hand): Localized strings in material3-a2ui (85 locales, 11 strings each), for example, are generated from upstream's res/values*/strings.xml into target/material3-a2ui-kmp/resources-generated/.

    upstreamSources(...) in target/build-logic wires all of this together for the compiler: it adds source/ to commonMain, excludes any relative paths present in the two overlay directories, and splices in the overlay files. If Google modifies an overlaid file in a future upstream release, the sha256 check in the manifest fails immediately during the build and points straight to the changed file. For day-to-day code reviews, we can focus on the hand-written code (overlay-manual/ and a2ui-compat/) and architectural changes.

Build Architecture

The Gradle build setup went through just as much iteration as the source layering. Because material3-a2ui and the 5 core packages underneath require different Kotlin and Compose Multiplatform versions, the repo has to be split into two separate Gradle b

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.