Overview
The new Rive Android runtime is nearly a complete rewrite of both the public API and the internal architecture. Conceptually most operations have an equivalent, even if the API is new. The first part of this guide covers basic operations and their equivalents. The second part covers features that are exclusive to either the legacy or new runtime. This guide is not meant to be exhaustive as it would be redundant with existing general documentation. Please refer to the relevant sections of the documentation for more details on specific topics. A number of features are no longer supported in the new runtime; these are covered in the Legacy Exclusive Features section. Most have workarounds or alternatives. These changes were made to simplify the API surface, reduce maintenance overhead, and prevent anti-patterns.Package
The legacy Rive Android runtime is provided in theapp.rive.runtime.kotlin package (+ .core). The new runtime is provided in the app.rive package (+ .core). This allows identical class names, such as Artboard to coexist without conflict. If you need to use identically named classes from both packages in the same file, you can use Kotlin’s import as feature to alias one of the imports.
Shared APIs
A few APIs are shared between the legacy and new runtimes. They are still in theapp.rive.runtime.kotlin package of the legacy runtime.
- The
Riveglobal object for initialization, including theRive.initmethod. - The
RiveInitializerXML initialization helper. - The fallback font APIs, including the
FontFallbackStrategyinterface and theFontFallbackStrategy.stylePickerglobal.
These shared APIs may change in the future to be fully separated with revised versions in the new package. This will only happen as a breaking change in a major version release.
Asynchronous APIs
Due to the new threading model based on theRiveWorker, almost all operations which return values that were originally synchronous on the main thread are now asynchronous suspend functions, e.g. loading Rive files and performing queries. You will need to call these functions from a coroutine context, such as within a LaunchedEffect in Compose or using lifecycleScope.launch in an Activity or Fragment.
The most common Compose operations are wrapped in helpers, such as rememberRiveFile, which expose the async state as a Result type for easier consumption in Composables. Other operations are “fire and forget”, such as creating artboards and view model instances from a loaded Rive file, or advancing a state machine.
Lifecycles
The legacy Rive Android runtime is View based, with theRiveAnimationView class managing its lifecycle based on the owning Activity or Fragment lifecycle. The Rive file’s lifetime is associated with the view’s, as well as the renderer, controller, and created objects such as artboards and state machines. These used hierarchical reference counting to manage their lifetimes.
The new runtime makes use of the AutoCloseable interface to manage lifetimes explicitly for objects such as the Rive file, artboards, and state machines. The worker by contrast is reference counted and owns all memory for resources it creates. When creating objects manually, you must close them to free their resources or they will last for the duration of the worker. Alternatively, you can use them with the use helper, which will call close at the end of its block. The worker itself must have all references released or it and its resources will leak.
In Compose, lifecycles are tied to remember Composables and use DisposableEffect to create and dispose of objects as needed, simplifying memory management.
RiveAnimationView to Rive
The legacy Rive Android runtime is View based and provided theRiveAnimationView class to display Rive animations. The name reflects the more limited feature set at the time of its creation, being mostly for animation playback.
The new API is Compose based, with the intention to provide a View API in the future. The main Composable is simply called Rive, reflecting the broader feature set and use cases it supports.
Setting a Local Raw Resource
The new API will use the I/O dispatcher by default to load Rive files asynchronously. This is different from the legacy runtime, which loaded files synchronously on the main thread. If you want to load files using a different threading model, load the resource using your preferred method and pass the bytes to a
RiveFileSource.Bytes source.Setting a Rive File from Bytes
Legacy RiveAnimationViewCaching a Rive File
See also Caching a Rive File for more details.
rememberRiveFile can be hoisted to a higher level Composable to live longer and be shared across multiple Rive instances.
Choosing an Artboard and State Machine
See also the artboard documentation for more details.
See also the state machine documentation for more details.
rememberArtboard and rememberStateMachine helpers to get these objects from a loaded RiveFile.
Setting the Fit and Alignment
See also the Layout documentation for more details.
Layout variant exposes the layout scale factor.
Auto Binding
See also the auto binding section in data binding for more details.
Playing, Pausing, and State Machine Settling
Legacy RiveAnimationView The legacy API includesplay() and pause() methods on the RiveAnimationView class to control playback of the animation. Notably, the paused state is the same as the settled state, which is not ideal. play() will both unpause and unsettle the state machine, causing it to advance.
playing parameter on the Rive Composable. Setting playing to false will pause the animation, while setting it to true will resume it. State machine settling and unsettling is done automatically and covers all scenarios that would require it.
Autoplay and Setting Initial Values
The legacy runtime includes anautoplay feature, defaulting to true, that automatically starts playing the given animation or state machine when the Rive file is loaded. This can be disabled to allow setting initial values before playback begins.
Legacy RiveAnimationView
autoplay feature as it is not necessary due to the decoupling of Rive files from their presentation. You can leave playing at its default value of true to achieve similar behavior. To set initial values before playback begins, you can set playing to false, update your data-bound properties, and then set playing to true to start playback.
Touch Pass-Through
Legacy RiveAnimationViewtouchPassThrough parameter on the Rive Composable. This is more nuanced, as it can be set to Consume (default behavior), Observe, or PassThrough. Observe shares only with ancestors in the Compose hierarchy, useful for not blocking scroll events, while PassThrough also shares with siblings (equivalent to the legacy behavior).
View Models
Legacy The legacy runtime includes aViewModel class retrieved from a File which corresponds to a view model in the Rive Editor. This class provides methods to query and create view model instances.
RiveFile class, where the view model name is included when required for queries. View model instances are specified by a ViewModelSource, which can be either Named or DefaultForArtboard. This ViewModelSource can then be converted into a ViewModelInstanceSource using the blankInstance, defaultInstance, or namedInstance helpers. This completed source can then be passed to rememberViewModelInstance or ViewModelInstance.fromFile.
View Model Instance Properties
Legacy The legacy runtime provides explicit property objects on theViewModelInstance class for querying and updating data-bound properties.
ViewModelInstance by name using getter and setter methods.
Bindable Artboards
Legacy The legacy runtime includes aBindableArtboard class that wraps a native Artboard and provides data-binding capabilities. This class is meant to limit the API surface and prevent anti-patterns by restricting direct access to the underlying artboard.
BindableArtboard class. Instead, the same Artboard class is used in both cases.
Loading Referenced Assets
Legacy The legacy runtime uses a “pull” model for loading referenced assets, where the runtime requests assets by callback as needed through theFileAssetLoader class or its subclasses. This allows lazy loading of assets, but removes control from the user for when assets are loaded.
Legacy RiveAnimationView
Default Layout Scale Factor
The legacy runtime uses the reported device density as the default scale factor when rendering Rive with Layout as the fit mode. The new runtime uses a default scale factor of 1.0, meaning Rive units map directly to screen pixels. In practice, matching density often results in visuals appearing too large. However, if that is the desired behavior and you want to match the legacy runtime, you can set the scale factor to the device density usingLocalDensity.
New Exclusive Features
A growing number of features are only available in the new runtime. These features were added to address limitations in the legacy runtime or to provide new capabilities that were not previously possible. Below is a list of such features along with brief descriptions.Logging
The new runtime includes a fine-grained, flexible logging system that allows you to capture logs at various levels (debug, info, warning, error) and redirect them to your preferred logging framework or sink. This is done by implementing theRiveLog.Logger interface and assigning the global RiveLog.logger property.
The library ships with a default implementation that logs to Android Logcat. Enable it with the following:
We may consider retrofitting more logging capabilities to the legacy runtime in the future, especially if doing so would illuminate a potential source for bugs.
Rendering to Bitmap
See the RiveSnapshotActivity example for a demonstration of this feature.
Bitmap, which can be useful for scenarios such as snapshot testing or rendering video encoded from data-bound Rive files into image frames on the edge (i.e. the user’s device). This is done using the RenderBuffer class or the onBitmapAvailable callback in the Rive Composable.
Rendering to a Bitmap was technically possible in the legacy runtime by rendering to a Canvas backed by a Bitmap or by sub-classing the renderer, but it was not a built-in feature and required more effort to implement.
There are no plans to retrofit this feature into the legacy runtime.
Updating a Data Bind Unsettles the State Machine
In the new runtime, updating a data-bound property automatically “unsettles” the state machine, causing it to advance and draw based on the new data. By comparison, the legacy runtime required you to callRiveAnimationView.play() after updating data-bound properties on a settled state machine to achieve the same effect.
We may consider retrofitting this behavior into the legacy runtime in the future as it is a common source of confusion. However, doing so would be a breaking change, and it may not be worth the disruption for existing users.
Tracking the Loading State of a Rive File
The new runtime provides aResult wrapper around Rive file loading operations, allowing you to track the state (loading, success, error) of a Rive file. This is useful for providing user feedback during loading or handling errors gracefully.
setRiveResource(), do not provide a way to track loading state or handle errors directly. Instead, the file must first be loaded using the File class. Loading is normally synchronous, though could be performed on a background thread. With some effort similar loading state tracking could be implemented.
There are no plans to retrofit this feature into the legacy runtime.
Legacy Exclusive Features
Some features are only available in the legacy runtime. This is usually because they were less commonly used, were complex in practice, or were difficult to maintain and support. Below is a list of such features along with guidance on how to handle their absence in the new runtime.View-Based API
The legacy runtime is built around theRiveAnimationView class, which is a subclass of Android’s TextureView (and subsequently View). This makes it easy to integrate into existing View-based Android applications. The new runtime is currently Compose-based and does not provide a View subclass. If you need to use Rive in a View-based application, you will need to set up a Compose environment within your View hierarchy using ComposeView.
There are plans to provide a View-based API in the future.
Frame Metrics
The legacy runtime includes support for frame metrics, providing some rendering performance numbers and potentially helping to identify bottlenecks. This is done by enabling frame metrics collection on theRiveAnimationView.
We will be adding performance monitoring in the future. The specific form it takes is to be determined.
CDN Assets
Legacy The Rive Editor allows marking an asset as “Hosted”, meaning it is uploaded to Rive’s CDN. The legacy runtime includes built-in support for loading these assets directly from the CDN when the Rive file is loaded. This is done automatically and by default when using theRiveAnimationView class.
Legacy RiveAnimationView
We will be adding a new API in a future update to query the asset manifest for a file, which will include URLs for hosted assets. This will allow you to load them using standard networking libraries and supply them to the Rive worker using existing asset APIs.
Setting a Rive File from Network
The legacy runtime provides built-in support for loading Rive files from network URLs using the now defunct Volley library. This includes methods such as: Legacy Builder APIRiveFileSource.Bytes source, passing the downloaded bytes. This source can be supplied to rememberRiveFile when using Compose or RiveFile.fromSource when working outside of a Compose context.
We are considering adding built-in network loading capabilities in future releases. If implemented, it would not use Volley, preferring a modern alternative. It would also likely be opt-in to avoid adding unnecessary dependencies for users who do not need network loading.
Rendering to Canvas
See also Choose a Renderer for more details.
Canvas. This was useful as a fallback for scenarios where the Rive Renderer wasn’t yet feature compatible. As we have improved the Rive Renderer, this use case has diminished.
The Canvas renderer is enabled with the following APIs.
Rive Global Default
There are no current plans to reintroduce Canvas rendering in the new runtime.
Artboard Volume
The legacy runtime can set an artboard’s audio volume through theArtboard.volume property or RiveAnimationView.setVolume(). This feature is not present in the new runtime.
We may consider adding audio features in the future, but there are no immediate plans to do so.
State Machine Inputs
See also the Inputs documentation for more details.
Events
See also the Rive Events documentation for more details.
RiveFileController.Listener interface.
There are no current plans to reintroduce event listening in the new runtime.
Text Runs
See also the Text documentation for more details.
There are no current plans to reintroduce text run support in the new runtime.
Linear Animations
See also the Linear Animation documentation for more details.
There are no current plans to reintroduce direct linear animation playback in the new runtime.
Multiple State Machines Per View
The legacy runtime allows multiple state machines to be associated with a singleRiveAnimationView instance. At the core runtime level there is no technical limitation, and each state machine is processed in sequence. In practice this leads to complexity and difficulty reasoning about state, especially when data binding is involved. Only the Android legacy runtime supported this capability among the various Rive runtimes.
The new runtime enforces a one-to-one relationship between Rive instances and state machines to simplify state management. If you need to manage concurrent, overlapping states, consider using state machine layers.
There are no current plans to reintroduce multiple state machines per Rive instance in the new runtime.
Observing State Machine State
The legacy runtime provides methods to observe which state is currently active in a state machine. This can be useful for triggering actions in your application based on the current state of the animation.There are no current plans to reintroduce state observation in the new runtime.
Single Touch Support
The legacy runtime supports single touch input, allowing only one touch interaction at a time. This is to maintain backwards compatibility with existing Rive files that were designed with single touch in mind. As such it is also the default behavior. Legacy RiveAnimationViewThere are no current plans to reintroduce single touch support in the new runtime.
Getting by Index
The legacy runtime provides methods to get artboards, animations state machines, view models, and view model instances by their index in addition to their name. This is rarely useful in scenarios where you want to iterate over all elements.There are no current plans to reintroduce getting by index in the new runtime.
Renderer Class
The legacy runtime includes theRenderer and RiveArtboardRenderer classes that allow you to override rendering behavior for Rive. It is difficult to use correctly, ensure proper life cycles, and maintain compatibility with the Rive Renderer as it evolves.
The new runtime does not include a Renderer class, focusing instead on the most common use cases. Other use cases, such as rendering to an Android Bitmap, are supported through dedicated APIs. Render loops are managed by the Rive Composable and execute on the RiveWorker.
There are no current plans to reintroduce a Renderer class in the new runtime.
Controller Class
The legacy runtime includes aRiveFileController class that provides methods to control playback, manage state machines, and observe state changes. It is tightly coupled to the RiveAnimationView.
The new runtime does not need a separate controller class, as control is provided directly through the Rive Composable and associated helpers.
There are no current plans to reintroduce a Controller class in the new runtime.