Overview
This guide covers best practices for building performant, reliable, and user-friendly AI applications with the RunAnywhere SDK.Model Selection
Choose the Right Model Size
Quantization Trade-offs
Memory Management
Unload Unused Models
Handle App Lifecycle
Check Memory Before Loading
Performance Optimization
Use Streaming for Better UX
Limit Token Generation
Pre-Download Models
Download models during onboarding for a better user experience:OnboardingScreen.tsx
Error Handling
Always Handle Errors Gracefully
Provide User Feedback
User Experience
Show Progress During Downloads
DownloadProgress.tsx
Add Typing Indicators
TypingIndicator.tsx
Graceful Degradation
Security & Privacy
Never Log Sensitive Data
Use Development Mode Appropriately
Disable Telemetry If Needed
Testing
Use Smaller Models for Testing
Mock for Unit Tests
React Native Platform Gotchas
iOS: react-native-screens Crashes
On iOS with New Architecture in RN 0.83+,react-native-screens crashes with errors like -[RCTView setColor:]. Use @react-navigation/stack (JS-based) instead of @react-navigation/native-stack, and mock react-native-screens in your Metro config:
metro.config.js
iOS vs Android New Architecture
New Architecture should be enabled on Android (newArchEnabled=true in gradle.properties) but disabled on iOS (set new_arch_enabled: false in Podfile). This avoids crashes with several native modules on iOS.
Custom Native Audio Module
Third-party audio recording libraries likereact-native-audio-recorder-player crash on iOS New Architecture. Build a custom native audio module using AVAudioRecorder (iOS/Swift) and AudioRecord (Android/Kotlin) that returns base64-encoded WAV data directly.
Audio Data Format
Audio is passed as base64-encoded strings between JavaScript and native code.RunAnywhere.transcribe() accepts base64-encoded WAV audio input. RunAnywhere.synthesize() returns base64-encoded float32 PCM audio. Use RunAnywhere.Audio.createWavFromPCMFloat32() to convert to a playable WAV file.
NitroModules Manual Setup
react-native-nitro-modules requires manual configuration on both platforms:
- iOS: Add
NitroModulespod manually inPodfile - Android: Include as a Gradle project in
settings.gradle
Duplicate Native Libraries (Android)
AddpickFirsts for libc++_shared.so, libjsi.so, libfbjni.so, libfolly_runtime.so, and libreactnative.so in your app’s build.gradle packagingOptions to resolve conflicts.
Node.js Path Fix (Android Studio)
Android Studio doesn’t inherit terminal PATH. Add explicit Node.js binary search paths in your rootbuild.gradle to fix node not found errors during Gradle builds.
Summary Checklist
Choose appropriate model size for your use case
Use streaming for better perceived performance
Unload models when not in use
Handle all error cases gracefully
Show progress during downloads and loading
Pre-download models during onboarding
Test on actual target devices
Use Development mode to iterate quickly
Never log sensitive user data
Provide clear feedback for all operations
Related
Configuration
SDK configuration
Error Handling
Handle errors gracefully
Quick Start
Getting started guide