> ## 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

> Fetch and render Metabind content in your Android apps with Jetpack Compose

The Metabind Android content SDK (`ai.metabind:metabind-content-android`) fetches content from Metabind and renders it as native Jetpack Compose, so you can update layouts and experiences over the air without a Play Store release. It ships from the `metabind-android` repository alongside the agent libraries.

<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-content-android:0.2.12")
    }
    ```
  </Tab>

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

<Note>
  Upgrading from the old `ai.metabind:metabind-android` artifact is a coordinate change only — the library keeps the `ai.metabind.metabind` package, so your imports don't change.
</Note>

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

## Configure endpoints and credentials

The SDK reads the Metabind API endpoints and credentials from your `AndroidManifest.xml` as `<meta-data>` entries. The endpoint entries (`url`, `ws.url`) are required — the client throws at startup without them. The credential entries are optional and default to an empty string when omitted:

```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" />
    <meta-data
        android:name="ai.metabind.metabind.api.key"
        android:value="${METABIND_API_KEY}" />
    <meta-data
        android:name="ai.metabind.metabind.organization.id"
        android:value="${METABIND_ORGANIZATION_ID}" />
    <meta-data
        android:name="ai.metabind.metabind.project.id"
        android:value="${METABIND_PROJECT_ID}" />
</application>
```

Supply the credential values through `manifestPlaceholders` in your `build.gradle.kts`, reading secrets from Gradle properties so they stay out of version control.

## 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>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.