Introducing Rive for Android Compose: Now in Technical Preview

Rive for Android Compose is now available in technical preview as of 10.3.0. This is a complete re-implementation of the Android Runtime with a new threading model, a streamlined API, and a more solid architecture built for the future.

Feedback Period

We’re in feedback mode, and now’s the time to kick the tires. The Compose API will stay in technical preview for at least a month, but likely longer, as we solicit feedback. That’s where you come in. Have suggestions or want something changed? Tell us (ideally with a sketch of your preferred alternative and why it’s better). Please leave feedback in this thread or in your Enterprise support channel. We’re excited to hear your thoughts!

⚠️ The technical preview period allows us to make breaking changes without any expectations of stability. Please don’t build anything for production during this time.

If you are evaluating Rive, Compose is likely your best option, barring stability issues, which we will address as quickly as possible. Direct support, hands-on support is available through enterprise channels. For any urgent projects, please contact us. Any breaking changes will always be announced with each release along with the rationale.

State of the Current View-Based API

During the feedback period, nothing will change with the current View-Based API (referred to going forward as the Legacy API). As of data binding artboards, no new features are planned for this API, allowing us to concentrate on the future with Compose.

This means that the Legacy API is in maintenance mode. Support will continue as usual for bug fixes through this period. Please continue to report them as normal. However, be aware that we will need to prioritize between new features and fixes to Compose vs. any issues with the Legacy API.

Once Compose exits technical preview, the Legacy API will be marked deprecated. This will be the time to migrate your work to Compose. The maintenance period will continue for an undetermined amount of time after the Compose release. We will have additional dates closer to this time.

If you wish to continue using Android Views, we will have a new implementation based on the new architecture (detailed later) available alongside Compose. Dates for this release are undetermined.

Setting Expectations

This first release of Compose is meant largely for API feedback. At this time, the API lacks automated testing, and therefore likely has bugs. We look to harden the implementation over the coming months with a full suite of tests. Any bugs reported by testers during this time will also be captured as tests to ensure no future regressions. You are also welcome to submit your own tests! We would greatly appreciate it.

Additionally, there are known missing features, detailed below. During the feedback period, we will be filling in these missing features and addressing bugs as they come up. Thank you for your patience.

By the time of full release, we expect Compose to be a much more reliable way to deploy Rive on Android.

Getting Started

To begin, simply update to 10.3.0. This includes the new APIs, which are available under the new app.rive package (as opposed to the prior app.rive.runtime.kotlin). The main composeable is RiveUI, a deliberate renaming from RiveAnimationView to show the increased scope of what is capable with Rive. However, to make use of it, you will need at minimum a Rive file, which can be loaded from either bytes or a reference to a raw .riv resource packaged with your app. There are plans to support network loading in the future, but for the present please download the .riv file yourself and supply the bytes instead.

There is an included sample app, ComposeActivity, also released with this version, which covers a number of concerns with the new API:

  • Hot swapping artboards, fit, and alignment

  • Data binding, including listening, setting, and preserving the view model instance between artboards

  • Font referenced asset loading

  • Command queue creation

  • Artboard querying


Please use this sample to discover some of how to use the new API. There is also full class and function API documentation for you to explore. Further docs on our docs website will follow.

Do be aware that during the technical preview period, you will need to opt into using these APIs using the @OptIn(ExperimentalRiveComposeAPI::class) annotation. This is to signal that these APIs are subject to change at any time.

The New Threading Model

As alluded to above, this is a fully new implementation of Rive on Android. We determined that our strategy for threading was brittle, relying on precise mutex locking, synchronization, ordering, and reference counting. This created a large surface area for bugs. After internal discussion, we decided to expose a new layer at the C++ runtime layer known as the Command Queue, which would be the new API surface for not only Android, but also the Unreal Engine rework and in the future all runtimes. It uses message passing through simple data with a narrow surface area for synchronization, and as a result we expect much better multithreaded stability.

A key change is that now the Android main (UI) thread never holds pointers to Rive memory. Instead, all memory is allocated on a worker thread and messages (or “commands”, hence the name) are passed across this barrier. When a resource is allocated, such as a file, asset, or artboard, the main thread only gets a “handle”. While similar to a pointer, handles can never be directly used, and must instead require a lookup on the worker thread before the pointer is used. This means that operations can fail in a use-after-free scenario, but not crash.

The Command Queue is the main thread component and it pairs 1:1 with a Command Server, which dispatches Rive commands to the existing C++ API. Resources are allocated on one Command Server. If you wish to have all Rive instances share resources, such as a font asset or instantiating a file multiple times, pass the same command queue to each creation. However, if you prefer to maximize multithreading throughput, you can create a new command queue for each, meaning each Rive instance gets its own worker thread. This flexibility is a great asset for the new architecture, along with the improved stability.

Future Features

As this is an initial release meant to solicit feedback as early as possible, some features are yet to be implemented at this time. These are:

  • Automated testing

    • As mentioned above, the test suite will be built out in parallel with user feedback.

  • Improved error handling

    • There are a number of failure scenarios that fail either silently or with a logged error. In the future, a broader range of APIs will surface errors. Expect APIs to be documented as throwing in the future.

  • Inputs, events, and text runs

    • These capabilities of these systems can be achieved with data binding. At this time, Compose (and the command queue) only support data binding. In the future, we may investigate folding the inputs API under the databinding API.

      • Events have a workaround through listeners, which can listen for an event to fire a trigger property. Please convert to this workaround if you currently rely on events for output to the runtime.

  • Images, lists, and artboard data binding

    • The second wave of data binding options will be supported in the near future.

  • Image decoding

    • Image decoding is not yet implemented. This is due to a C++ level integration issue. We plan to resolve this in a follow-on release. For now, decoding images with throw a “not implemented” exception.

  • Touch pass through

    • The Legacy API recently added the ability to toggle whether touch events are absorbed by the Rive surface. This does not yet exist on Compose but will be added in a future release.

  • Scale factor

    • With the introduction of Layouts, the Legacy API added an option to scale the Rive UI by a given factor. We will consider a similar option for Compose in response to user feedback.

  • Playing and pausing

    • In this release, all playback is handled by the state machine. We will consider a play/pause boolean parameter for Compose in response to user feedback.

  • Auto-binding

    • With the introduction of data binding, the Legacy API added an option to auto-bind the default view model instance at creation time. We plan to introduce a similar option for Compose. For now you must create a view model instance and assign it.

  • Audio Engine

    • The audio engine is not yet being initialized, and therefore audio assets do not play as expected. This will be added in a future release.

  • Network file loading

    • A convenience wrapper to load Rive files from the network. For now, please download yourself and supply the bytes.

  • Views API

    • For this first release, the command queue implementation only supports Compose. There are plans to include a Views API as well. We will need to decide whether to support this through Compose View, simplifying to one implementation, or as a completely separate implementation, which would allow making the Compose dependency optional.

  • Vulkan

    • Vulkan is not supported on the Legacy API either, but support for Compose is forthcoming. We may release Compose without Vulkan support, which would follow later in the year.

  • Canvas rendering

    • The Rive Renderer is the only supported way to render Rive files in Compose. We have no plans to add an option for Android Canvas rendering unless strongly requested by feedback.

  • Benchmarking

    • We plan to create and release benchmarks to compare CPU, GPU, memory, and disk usage metrics, including in comparison to the Legacy API.

Areas of Focus for Feedback

We welcome all feedback for the new API, and it will all be taken into consideration. To seed some initial thinking, below is a list of some decision points, what we decided, and why.

  • Making the command queue explicit

    • Rationale: There was the option of making the command queue an implementation detail, and earlier it was. But exposing the choice of fan-out vs. memory sharing seems like the right approach, at the expense of some mental overhead.

  • Making CommandQueue a default argument on rememberRiveFile

    • Rationale: This is a question of what should the default arrangement be: a singular command queue, or one per file? The optional parameter enables the latter and one less mandatory line of setup (rememberCommandQueue). But it may be that by default users would rather share resources. This is harder to accomplish. The best approach may be through CompositionLocal, but that still requires setup. Another option is to just make the argument non-default, forcing all users to make a command queue before getting started.

  • Moving the package to just app.rive

    • Rationale: The extra package specificity didn’t add much value. There is an open question of how much package subdivision to add beyond this. Currently all public APIs are at this level and internal details are in .core. There are still a few areas using the Legacy API which will be moved over to the new package when it is deprecated.

  • rememberRiveFile produces a Result which may be Loading, Error, or Success

    • Rationale: This adds explicitness to the three states of the Rive file. This requires explicit handling as well, ideally with a when statement as seen in the sample. It remains to be seen if there can be usability improvements around this.

  • Compose is now an added dependency to the Rive library

    • Rationale: This increases the binary size. However, our intention is to be Compose-first. In the future we could consider making Compose an add-on, if we do a View-based implementation without Compose.

  • Fallback fonts use the existing API

    • Rationale: There was no need to change this. Eventually its location and exact semantics may change.

  • View model instance properties have an initial value set by the user

    • Rationale: Because all APIs are now necessarily async due the new threading model, that means there is no initial value for a view model instance property. The API for a property accepts a user-defined initial value as a placeholder during the initial fetch. The user expected to choose a safe value. We could additionally consider an API that instead exposes a nullable, with null during the initial fetch.

  • Push vs. pull referenced asset API, i.e. assets are supplied upfront

    • Rationale: This is the new approach adopted by the command queue. The Legacy API used a “pull” based API, where the user is requested and fulfills each asset on demand. The new approach is a “push” API where the user supplies all referenced assets to the command queue to make them available to any Rive file loaded on that queue. We’re curious to hear feedback on this new approach compared to the old.

  • Making the artboard a first-class object rather than string-based

    • Rationale: Originally it was string based, but for queries that used the artboard, such as list of state machines or default view model, it required instantiating a temporary artboard just to do the query, and then deleting it. Additionally, with it being an explicit object, it could be used to instantiate multiple RiveUI instances.

  • Using a builder pattern for ViewModelSource/ViewModelInstanceSource

    • Rationale: This API attempts to cover the permutations of how to create view models and how to create view model instances. This seemed like the natural fit.