Android Runtime Rules
Applies to: Kotlin/Java files in /valdi/src/valdi/android/ and related Android runtime code
Overview
The Valdi Android runtime bridges TypeScript/Valdi components to native Android views. It's implemented in Kotlin and C++ (via JNI).
Code Style
- 4-space indentation for Kotlin/Java
- Follow Kotlin coding conventions
- Use Kotlin features (data classes, extension functions, etc.)
Key Concepts
View Rendering
- Valdi components map to Android Views
- View recycling for performance
- Efficient view updates
Platform Bridge
- JNI bridge to C++ runtime
- Kotlin/Java to native code communication
- Performance-critical paths
Common Patterns
Bazel Android Targets
android_library(
name = "valdi_android",
srcs = glob(["**/*.kt", "**/*.java"]),
)
View Binding
- Custom view implementations
- Attribute binding for Valdi properties
- Event handling
Testing
# Run Android runtime tests
bazel test //valdi:test_java
# Run with coverage
bazel coverage //valdi:test_java
Test files are in /valdi/test/java/
Building
# Build Android runtime library
bazel build //valdi:valdi_android
# Test with hello world app
valdi install android
cd apps/helloworld
valdi install android
Platform-Specific Notes
- API Level - Be mindful of minimum API level
- Android NDK - C++ integration via NDK
- Permissions - Handle runtime permissions appropriately
- Lifecycle - Android Activity/Fragment lifecycle
Important
- Performance - View creation and updates are critical
- Memory - Be careful with leaks (Activity context)
- Threading - UI thread vs background threads
- Compatibility - Support multiple Android versions
More Information
- Runtime source:
/valdi/src/valdi/android/ - Runtime tests:
/valdi/test/java/ - Build config:
/valdi/BUILD.bazel - Framework docs:
/AGENTS.md