rive-app / rive-app/rive-android
StrictMode violation: system font list loads on main thread
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 538
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
Description
When a RiveAnimationView is attached on Android with a custom FileAssetLoader that calls FontHelper.getSystemFontList(), StrictMode reports an UnbufferedIoViolation. The call performs disk IO (parsing fonts.xml) on the main thread during view attachment, so any app that enables StrictMode and loads a Rive animation with text will hit the violation.
Provide a Repro
class SampleActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build()
)
setContentView(
RiveAnimationView(this).apply {
setRiveResource(R.raw.sample_with_text)
setAssetLoader(object : FileAssetLoader() {
override fun loadContents(asset: FileAsset, inBandBytes: ByteArray): Boolean {
if (asset is FontAsset) {
if (inBandBytes.isNotEmpty() && asset.decode(inBandBytes)) return true
// This triggers FontHelper.getSystemFontList() -> disk IO on main thread.
val families = FontHelper.getSystemFontList()
val firstFont = families.firstOrNull()?.fonts?.values?.firstOrNull()?.firstOrNull()
return firstFont?.let { asset.decode(FontHelper.getFontBytes(it)) } ?: false
}
return false
}
})
}
)
}
}
- Enable StrictMode as above.
- Launch the activity so RiveAnimationView is attached.
- Observe the StrictMode logcat entry: StrictMode policy violation: UnbufferedIoViolation originating from FontHelper.getSystemFontList() during SystemFontsParser.parseFontsXML.
Source .riv/.rev file
Any .riv file
Expected behavior
Loading system fonts (or any font metadata) should not perform disk IO on the main thread. The call should either run asynchronously, cache results before UI usage, or expose an async API so apps can avoid StrictMode violations.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing FontHelper.getSystemFontList() from the custom FileAssetLoader during RiveAnimationView attachment, then inspect the SystemFontsParser.parseFontsXML path mentioned in the report. Determine how system font metadata is loaded and define a completion check that no disk IO occurs on the main thread while font loading remains usable for text assets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100