Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

How to Use Rive Data Binding & ViewModels in Android & Jetpack Compose

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: How to Use Rive Data Binding & ViewModels in Android & Jetpack Compose, with Charmotion demo characters

In Android Jetpack Compose, you load a .riv file, look up a ViewModel by name, create a ViewModelInstance and bind it, then read and write its properties from Kotlin. Rive Data Binding lets designers define the typed properties in the editor while app code changes them at runtime. The steps below use a mood number for a mascot.

Key takeaways

  • Rive Data Binding lets Kotlin code read and write typed ViewModel properties that a designer defined in the Rive editor.
  • Add app.rive:rive-android, call Rive.init once at app start, and remember that the Compose API is labeled Beta.
  • Get the instance with ViewModelSource.Named and rememberViewModelInstance so it survives recomposition.
  • Property names and types must match the editor exactly, and most failures come from a mismatch.
  • Check the runtime version before you copy code, because data binding APIs change between releases.

What does Rive Data Binding do in an Android app?

Rive Data Binding connects a Rive file to your app code. A designer defines typed properties in the Rive editor through a ViewModel, and your Kotlin code reads and writes live values on that ViewModel while the animation runs. The app sets a number and the character reacts, without a new export or a new .riv file.

This guide covers how to use Rive Data Binding in Kotlin and Android Jetpack Compose from setup to a working mascot. It assumes you already have a .riv file with at least one ViewModel and one property to drive. If you are still choosing between data binding and state machine inputs, read Rive data binding vs state machine inputs first.

The property types come from the editor. Rive's property types page lists Number, String, Boolean, Color, Enum, Trigger, Image, nested View Model and List. Pick the type that matches the value your app holds: a mood number, a display name, or a feature flag.

The same ViewModel idea works on other platforms. For the Apple side, see how to use Rive in SwiftUI, and for web code, see how to use Rive in React and Next.js. The Kotlin API differs from both, so the code below does not carry over directly.

How do you set up the Rive Android runtime for Jetpack Compose?

Add the runtime from Maven Central. Rive's Android docs recommend the app.rive:rive-android artifact at version 11.17.0 as of December 2026. Check the docs page for a newer release before you pin the version, and keep every Rive dependency on the same release line.

dependencies {
    implementation("app.rive:rive-android:11.17.0")
}

Initialize the runtime once before any Rive view loads by calling Rive.init(context). The docs list Jetpack App Startup as an optional way to run that call. The simplest route is an Application class, which is also how a community tutorial on a Compose pull-to-refresh example sets it up.

class MascotApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Rive.init(this)
    }
}

Declare the class in AndroidManifest.xml with android:name so Android uses it at launch. Keep the init call in one place that always runs, so every screen that shows a Rive animation shares the same setup. For a wider walkthrough of adding animation to a Compose project, see how to add animation to an Android app.

The newer Compose API uses a Rive composable as its entry point. Rive's docs label it Beta. Read its parameter list on the Android runtime page before you copy any snippet, because Beta APIs can change between releases.

How do you create a ViewModelInstance and bind it to a composable?

Start with a named ViewModel in the .riv file. The name is what your code asks for, so agree on it with the designer before anyone writes Kotlin. Rive's Android data binding docs show ViewModelSource.Named to choose a ViewModel by name, and file.getViewModelByName to fetch one outside Compose.

In Compose, the shortest path is rememberViewModelInstance. It creates a default instance and keeps it across recompositions, so the animation is not rebuilt every time the screen redraws.

val viewModelInstance = rememberViewModelInstance(
    riveFile,
    ViewModelSource.Named("CharacterViewModel").defaultInstance()
)

Here riveFile is the file you loaded from your app resources, and CharacterViewModel is the name the designer gave the ViewModel in the editor. Pass viewModelInstance into the Rive composable so the animation reads from it. The docs also describe auto-binding, which connects a default instance to the animation without extra wiring. Confirm the exact auto-binding behavior on the data binding page for the version you ship.

Load the file once per screen and reuse it. Loading the same .riv on each recomposition wastes work, and it makes it harder to tell whether a stale instance is the cause of a bug.

How do you read and write ViewModel properties from Kotlin?

Read and write properties on the instance, using the accessor that matches the type set in the editor. Store each property name in one constant. A rename in Rive then breaks one line in your code, not several scattered strings that fail without warning.

  • Number: a mood or a progress value, such as 0 to 100.
  • String: a display name, a message or an error label.
  • Boolean: a flag, such as whether small accents are shown.
  • Trigger: a one-off event such as a tap. Each set fires it once.

Enum, Color, Image, nested View Model and List properties follow the same pattern with their own types. The property types page lists each one.

A concrete example: a mascot that should look happy after a successful save. Your state holder sets the mood number to the value the designer mapped to happy, and the animation blends into that state. The app code does not need to know the state machine's internal names, only the ViewModel property. For a full mapping of app states to moods, see how to drive Rive character mood states from app state.

Write values when your app state changes, not on every recomposition. Setting the same value on each frame asks the animation to update for no reason, and it hides the real moments when the state moved.

What happens when a list of ViewModel instances changes at runtime?

A List property holds nested ViewModel instances. Rive's Android data binding docs describe adding, removing and swapping items at runtime. That suits a feed of cards, a row of avatars, or a set of badges that change as the user earns them.

Update the list from your state holder, not from inside the composable. One update path makes it easier to trace why an item appeared, disappeared or moved. When you swap an instance, keep a reference to the one the screen is showing, so the UI and the file never disagree about which item is active.

Drop instances that the screen no longer uses so memory stays predictable. Rive's Flutter runtime exposes disposal directly on each instance; for Android, follow the cleanup rules on the data binding page for your version. The Flutter version of this pattern is covered in how to use Rive data binding in Flutter.

Android runtime v11.13.0 added font data binding, and the PropertyDataType enum gained an ASSET_BLOB value, according to Rive's October 2026 runtime update. If a list item needs a custom font or an asset, check that your runtime version includes those types before you design around them.

Why does my Rive data binding not update, and how do you fix it?

Most failures come from a short list of causes. Check them in this order before you change the animation file.

  1. The ViewModel name does not match the file. Names are matched exactly, so copy them from the editor instead of retyping them.
  2. The property name or type differs from the editor. Writing a string to a number property will not show a change. Compare the name and type in both places.
  3. Rive.init was never called, or ran after the first view. Move the call into the Application class so it runs at app start.
  4. A new instance is created on every recomposition. Use rememberViewModelInstance, as shown above, so the instance stays the same.
  5. The runtime is older than the feature. Data binding support differs between releases. Match the version in the docs to the features your file uses.

If the animation still ignores your changes, reduce the problem to one property and one screen. A minimal case shows whether the problem is in the file, the binding or the surrounding state code.

Charmotion characters follow the same pattern: each exported .riv includes a CharacterViewModelMachine with a number property named mood, where idle is 0, happy is 1 and loading is 5. Charmotion's how it works page lists the other mood numbers.

How to use Rive Data Binding in Kotlin and Android Jetpack Compose

  1. Add the Rive Android runtime. Add app.rive:rive-android at the version Rive's Android docs recommend, 11.17.0 as of December 2026, to your Gradle dependencies, and check the docs for a newer release.
  2. Initialize Rive once at app start. Call Rive.init(context) from an Application class declared in AndroidManifest.xml so the runtime is ready before any Rive view loads.
  3. Get a ViewModel instance. Load the .riv file from your resources, then use ViewModelSource.Named with the ViewModel name from the editor and rememberViewModelInstance so the instance is kept across recompositions.
  4. Read and write typed properties. Set Number, String, Boolean or Trigger properties through the accessor that matches each type in the editor, storing property names in constants.
  5. Update lists and check the binding. Change List properties from your state holder, drop unused instances, and if values do not update, check the ViewModel name, property type, Rive.init placement and runtime version.

Frequently asked questions

Can I use Rive Data Binding without Jetpack Compose on Android?

Yes. Rive's Android docs describe two APIs, and the Compose one is the newer of the two. This guide uses Compose because it fits Kotlin screens built with it. The Compose API is labeled Beta in the docs, so check its status on the Android runtime page before you ship it to production.

Does Rive Data Binding work with Compose Multiplatform?

A community wrapper called Rive CMP depends on the Android Kotlin runtime and exposes an onViewModelInstance callback for binding a ViewModel. It is a third-party project, not an official Rive package, so check its repository for maintenance and release dates before you depend on it.

Which Rive Android version should I use for data binding?

Rive's Android docs recommend 11.17.0 as of December 2026. Release notes from October 2026 show that v11.13.0 added font data binding and an ASSET_BLOB property type, so newer releases carry more binding features. Use the version on the docs page and read its release notes for the features you need.

Do I need a paid Rive plan to bind data in my app?

Rive's Free plan exports .riv files that play a Rive splash screen, while paid plans export without it. The runtime that plays the file is open source. For editor plan details and current limits, check Rive's pricing page, and see /guides/is-rive-free-pricing for an overview.

Sources

Related guides