> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metabind.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Android SDK

> Integrate server-driven UI into your Android apps with Jetpack Compose

The Metabind Android SDK (`metabind-android`) lets you render server-driven content in your Kotlin applications. Build dynamic experiences that update instantly without app store releases.

<Card title="View on GitHub" icon="github" href="https://github.com/metabindai/metabind-android">
  `metabind-android` — source code, issues, and releases.
</Card>

## Requirements

| Requirement | Version               |
| ----------- | --------------------- |
| Android     | 8.0 (API 26) or later |
| UI toolkit  | Jetpack Compose       |
| JDK         | 21                    |

## Installation

Add the SDK to your module's dependencies. It pulls in `bindjs-android` (the Compose renderer) transitively.

<Tabs>
  <Tab title="build.gradle.kts">
    ```kotlin theme={null}
    dependencies {
        implementation("ai.metabind:metabind-android:0.0.10")
    }
    ```
  </Tab>

  <Tab title="build.gradle">
    ```groovy theme={null}
    dependencies {
        implementation 'ai.metabind:metabind-android:0.0.10'
    }
    ```
  </Tab>
</Tabs>

See the [repository README](https://github.com/metabindai/metabind-android) for the Maven repository configuration.

## Configure endpoints

The SDK reads the Metabind API endpoints from your `AndroidManifest.xml` as `<meta-data>` entries. Set both, or the client throws at startup:

```xml theme={null}
<application>
    <meta-data
        android:name="ai.metabind.metabind.url"
        android:value="https://api.metabind.ai/graphql" />
    <meta-data
        android:name="ai.metabind.metabind.ws.url"
        android:value="wss://ws-api.metabind.ai" />
</application>
```

## Quick start

Render content by its ID with the `MetabindView` composable. It fetches the content and its components, renders them as native Compose, and handles loading and error states:

```kotlin theme={null}
import androidx.compose.runtime.Composable
import ai.metabind.metabind.view.MetabindView

@Composable
fun ContentScreen() {
    MetabindView(contentId = "your-content-id")
}
```

To receive live updates when the content changes in Metabind, opt in to the WebSocket subscription:

```kotlin theme={null}
MetabindView(contentId = "your-content-id", enableSubscription = true)
```

## Core concepts

### MetabindView

`MetabindView` is the primary way to display content. Backed by `MetabindViewModel`, it:

* Fetches the content and its required components
* Renders the UI through the BindJS Compose runtime
* Subscribes to real-time updates when `enableSubscription` is `true`
* Exposes a `StateFlow<UiState>` of `Loading | Success | Error`

```kotlin theme={null}
MetabindView(contentId = "content-id", enableSubscription = false)
```

Two focused variants ship alongside it:

* **`PreviewView(contentId =)`** — a fixed-size (150×150 dp) live preview.
* **`ThumbnailView(contentId =)`** — an offscreen-rendered bitmap snapshot, for non-interactive thumbnails.

### ComponentRepository

For direct data access below the view layer, `ComponentRepository.get(context)` exposes the Apollo-backed fetchers and a dual-layer cache (10 MB in-memory chained to a SQLite store). It returns `suspend` functions and Kotlin `Flow`s — for example `getContentByToken(token)` for a one-shot read and `subscribeToPreviewByToken(token)` for a live stream over WebSocket.

## Real-time updates

For live content, either pass `enableSubscription = true` to `MetabindView` or subscribe directly through `ComponentRepository`. `subscribeToPreviewByToken(token)` returns a `Flow` that emits whenever the content changes in Metabind:

```kotlin theme={null}
val repository = ComponentRepository.get(context)

repository.subscribeToPreviewByToken("your-content-id").collect { component ->
    // Re-render or update state with the new content
}
```

The client reconnects the WebSocket automatically, with backoff, if the connection drops. For cache-then-network delivery, `watchPreviewByToken(token)` returns a `Flow<Result<PreviewComponent>>`.

## Direct GraphQL access

For data access below the view layer, `ComponentRepository` exposes `suspend` fetchers and Kotlin `Flow`s over the same GraphQL API and cache. See the [repository on GitHub](https://github.com/metabindai/metabind-android) for the available methods, and the [GraphQL docs](/graphql/overview) for the API itself.

## Next steps

<CardGroup cols={2}>
  <Card title="Build components" icon="puzzle-piece" href="/guides/building/authoring-components">
    Create custom components for your app.
  </Card>

  <Card title="BindJS reference" icon="code" href="/bindjs/introduction">
    Learn the component authoring language.
  </Card>

  <Card title="Managing content" icon="file-lines" href="/content/overview">
    Understand how to structure content.
  </Card>

  <Card title="iOS SDK" icon="apple" href="/content/mobile-sdks/ios-sdk">
    The iOS equivalent.
  </Card>
</CardGroup>
