Android
Android runtime for Rive

Overview

This guide documents how to get started using the Android runtime library. Rive runtime libraries are open-source. The source is available in its GitHub repository. This library contains an API for Android apps to easily integrate Rive assets.

Getting Started

Follow the steps below for a quick start on integrating Rive into your Android app.

1. Add the Rive dependency

Add the following dependencies to your build.gradle file in your project:
1
dependencies {
2
implementation 'app.rive:rive-android:3.0.10'
3
// During initialization, you may need to add a dependency
4
// for Jetpack Startup
5
implementation "androidx.startup:startup-runtime:1.1.0"
6
}
Copied!

2. Initializing Rive

Rive needs to initialize its runtime when your app starts.
It can be done via an initializer that does this for you automatically. The initialization provider can be set up directly in your app's manifest file:
1
<provider
2
android:name="androidx.startup.InitializationProvider"
3
android:authorities="${applicationId}.androidx-startup"
4
android:exported="false"
5
tools:node="merge">
6
<meta-data android:name="app.rive.runtime.kotlin.RiveInitializer"
7
android:value="androidx.startup" />
8
</provider>
Copied!
Otherwise this can be achieved by calling the initializer in your code:
1
AppInitializer.getInstance(applicationContext)
2
.initializeComponent(RiveInitializer::class.java)
Copied!
If you want to initialize Rive yourself, this can be done in code:
1
Rive.init(context)
Copied!

3. Add RiveAnimation to your layout

The simplest way to get a Rive animation into your application is to include it as part of a layout. The following will consist of the Rive file loaded from the raw resources and auto-play its first animation. This assumes you have taken a downloaded .riv file (i.e off_road_car_blog.riv) and placed it in your raw resources folder.
1
<app.rive.runtime.kotlin.RiveAnimationView
2
android:layout_width="match_parent"
3
android:layout_height="match_parent"
4
app:riveResource="@raw/off_road_car_blog" />
Copied!
Another way to load a Rive file in is by referencing the URL where the asset lives (see Internet Permissions section below for an extra step in setup):
simple.xml
1
<app.rive.runtime.kotlin.RiveAnimationView
2
android:layout_width="match_parent"
3
android:layout_height="match_parent"
4
app:riveUrl="https://cdn.rive.app/animations/vehicles.riv" />
Copied!
When setting your context views, this might look like
1
import android.os.Bundle
2
import androidx.appcompat.app.AppCompatActivity
3
4
class SimpleActivity : AppCompatActivity() {
5
6
override fun onCreate(savedInstanceState: Bundle?) {
7
super.onCreate(savedInstanceState)
8
setContentView(R.layout.simple)
9
}
10
}
Copied!

Internet permissions

If you're retrieving Rive files over a network, your app will need permission to access the internet:
AndroidManifest.xml
1
<uses-permission android:name="android.permission.INTERNET" />
2
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Copied!
Note that this isn't necessary if you include the files in your Android project and load these in as a raw resource.
See subsequent Runtime pages to learn how to control animation playback, state machines, and more.

Resources