How rive-app/rive-android works
Project’s Domain and Purpose
• Rive Android is an Android runtime library that enables loading and interacting with Rive animations in Android apps.
• The README emphasizes integration with Android, showcasing examples on how to load animations, control state machines, deal with rendering, and more.
• The inclusion of a full-featured example app (in the “app/” directory) and a Kotlin version under the “kotlin/” folder reinforces that this is a runtime library with both usage examples and deep integration (including native C++ bindings via JNI).
File Structure
• Top-level files and folders (such as .github, docs, app, kotlin, compatibilitytest, submodules) indicate multiple components:
• .github, gradle, and scripts: These relate to CI/CD, building, deployment, and release automation.
• The “app/” directory: Contains a sample Android application with multiple example activities that showcase runtime usage (with activities, layout XMLs, and resource files).
• “kotlin/”: Contains a rich codebase for the Android runtime implemented in Kotlin with additional native C++ integration (found in src/main/cpp). This part comprises core logic (state machines, artboards, renderers, controllers), helper libraries, and error handling.
• “compatibilitytest”: Provides additional testing to ensure module integration with various native libraries.
• “docs/”: Contains extensive documentation regarding APIs (for both Kotlin and C++ components).
• “submodules/rive-runtime”: Likely references a submodule containing core runtime functionality or a dependency shared with other platforms.
• Notice the separation of concerns. The source code is broken down by feature areas (e.g., controllers, core logic, renderers) which suggests an MVC or layered architecture for how the runtime interacts with both higher-level user interfaces (RiveAnimationView) and lower-level native rendering components.
Main Components and Their Relationships
• Android Application Layer:
• Example App: Located in the “app/” directory, it demonstrates how to integrate and use the Rive runtime, showcasing different activities, layouts, and state machine interactions.
• Rive Android Runtime Library:
• UI Components: RiveAnimationView (and related view controllers) which are integrated into Android UI.
• Core Runtime Layer: The core Kotlin packages (e.g., app/rive/runtime/kotlin/core) that manage animation playback, state machines, artboards, and event handling.
• Controllers & Renderers: Classes that manage file loading (RiveFileController), state management, and render loop handling (including Renderer objects).
• Native (C++) Layer:
• Found in kotlin/src/main/cpp, C++ bindings, helpers, and models provide rendering support and low-level performance. The architecture uses JNI channels to bridge between Kotlin and these native libraries.
• CI/CD and Build Infrastructure:
• The .github workflows, gradle scripts, and release-related scripts (in .github/scripts/release) indicate that automated builds, tests, code quality checks, and deployments are integral.
• Documentation & Testing:
• The “docs” directory provides extensive API documentation (including docs for Kotlin usage).
• The “compatibilitytest” and “androidTest” directories in both app and kotlin provide tests that ensure proper behavior and integration.
Architectural Patterns and Design Principles
• Modular Design: The separation into sample apps, runtime core, native layer, and tests indicates a modular approach.
• Layered Architecture:
• Presentation Layer (Android views and activities)
• Runtime/Core logic (Kotlin-based controllers, artboards, state machines)
• Native Rendering Layer (C++ modules accessed via JNI)
• Separation of Concerns: Different modules handle UI, animation control, native rendering, and animation assets loading.
• Use of Dependency Injection/Abstraction: For example, the ability to select a renderer via XML or programmatically (using Rive.init with a default renderer) shows that the project supports pluggable design elements.