Example of how to use Rive with Jetpack Compose
- Empty (Compose) Activity with
Android Studio Hedgehog | 2023.1.1 Canary 8
Build #AI-231.9011.34.2311.10290408, built on June 9, 2023
Runtime version: 17.0.6+0-17.0.6b829.9-10027231 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.4
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Metal Rendering is ON
Registry:
external.system.auto.import.disabled=true
debugger.new.tool.window.layout=true
ide.text.editor.with.preview.show.floating.toolbar=false
ide.experimental.ui=true
Non-Bundled Plugins:
com.developerphil.adbidea (1.6.11)
implementation("app.rive:rive-android:5.0.0")
implementation("androidx.startup:startup-runtime:1.1.1")
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="com.rive.example.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data android:name="app.rive.runtime.kotlin.RiveInitializer"
android:value="androidx.startup" />
</provider>
Riv Files can be browsed here.
AndroidView(
modifier = Modifier,
factory = { context ->
RiveAnimationView(context).also {
it.setRiveResource(
resId = R.raw.basketball,
alignment = CENTER
)
}
}
)