rive-android
rive-android copied to clipboard
I tried creating a sample app. But, not able to play animation
Description
I tried creating a sample app. But, not able to play animation and app is crashing with
Caused by: app.rive.runtime.kotlin.core.errors.ViewModelException: No default ViewModel found for artboard State change. (Ask Gemini)
at app.rive.runtime.kotlin.core.File.defaultViewModelForArtboard(File.kt:172)
at app.rive.runtime.kotlin.controllers.RiveFileController.setupScene$kotlin_release(RiveFileController.kt:450)
at app.rive.runtime.kotlin.RiveAnimationView$1$1$1.invoke(RiveAnimationView.kt:374)
at app.rive.runtime.kotlin.RiveAnimationView$1$1$1.invoke(RiveAnimationView.kt:372)
at app.rive.runtime.kotlin.RiveAnimationView.loadFileFromResource(RiveAnimationView.kt:440)
at app.rive.runtime.kotlin.RiveAnimationView.<init>(RiveAnimationView.kt:372)
.. 29 more
Provide a Repro
package com.example.rivesample
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
class AnotherActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_another)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AnotherActivity">
<app.rive.runtime.kotlin.RiveAnimationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:riveAutoBind="true"
app:riveAutoPlay="true"
app:riveResource="@raw/loading_rive" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.rivesample
import android.app.Application
import app.rive.runtime.kotlin.core.Rive
/**
* Application class to initialize rive
*/
class App : Application() {
override fun onCreate() {
super.onCreate()
Rive.init(this)
}
}
Source .riv/.rev file
Expected behavior
Ideally shouldn't crash
Device & Versions (please complete the following information)
- Device: Pixel 4a
- Compile and target : 35
- Lib version : 10.1.6
Thanks for reporting @EpariNigam, it looks like we're trying to initialize data binding for a .riv file that doesn't have it configured. We'll get this fixed.
For you to step around this in the meantime, you can set app:riveAutoBind="false" which is what you'd want to set it to if you're not making use of data binding.
Understood. Thanks for the quick reply. With auto bind false, it is working fine.