This guide walks you through setting up React Native ExecuTorch in a bare React Native project (created without Expo).Documentation Index
Fetch the complete documentation index at: https://mintlify.com/software-mansion/react-native-executorch/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, ensure you have:- Node.js 18 or later
- React Native development environment set up (React Native CLI Setup)
- iOS 17.0+ or Android 13+ device/emulator
- Xcode 14+ (for iOS development)
- Android Studio (for Android development)
- At least 4GB of RAM on your device for LLMs
Minimum Version Requirements
- iOS: 17.0+
- Android: API level 13+
- React Native: 0.81+
Step 1: Create or Update React Native Project
Create a New Project
Update Existing Project
Ensure you’re on React Native 0.81 or later:Step 2: Install Dependencies
Install React Native ExecuTorch and bare resource fetcher:Step 3: Link Native Dependencies
iOS Setup
Install CocoaPods dependencies:Android Setup
The Android dependencies should link automatically through autolinking. If you encounter issues, verify yourandroid/build.gradle includes:
Step 4: Configure Native Dependencies
Configure react-native-fs
No additional configuration needed. The library is ready to use after installation. See the react-native-fs documentation for advanced configuration.Configure react-native-background-downloader
iOS Configuration
Add background modes to yourios/YourApp/Info.plist:
Android Configuration
Add permissions toandroid/app/src/main/AndroidManifest.xml:
Step 5: Enable New Architecture
React Native ExecuTorch requires the New Architecture.iOS (New Architecture)
Editios/Podfile:
Android (New Architecture)
Editandroid/gradle.properties:
Step 6: Initialize Resource Fetcher
Update your app’s entry point (usuallyindex.js or App.tsx):
Step 7: Run Your First Model
Create a component to test model loading:Step 8: Build and Run
iOS
ios/YourApp.xcworkspace in Xcode and build from there.
Note: Test on physical devices for accurate performance. Simulators may not reflect real-world behavior.
Android
Start Metro bundler:Using BareResourceFetcher Features
Loading Models from Different Sources
Managing Downloads
react-native-background-downloader.
Managing Storage
File Storage Location
BareResourceFetcher stores files in:- iOS:
{DocumentDirectory}/react-native-executorch/ - Android:
{DocumentDirectory}/react-native-executorch/
Platform-Specific Configuration
iOS: Increase Memory Limit
For large models, you may need to increase the memory limit in Xcode:- Open
ios/YourApp.xcworkspace - Select your target
- Go to “Signing & Capabilities”
- Add “Increased Memory Limit” capability (if available)
Android: Increase Heap Size
Editandroid/app/src/main/AndroidManifest.xml:
android/gradle.properties:
Troubleshooting
Native Module Not Found
If you see “Native module not found” errors:- Clean and rebuild:
- Reset Metro cache:
Resource Fetcher Not Initialized
Error:ResourceFetcherAdapterNotInitialized
Solution: Ensure initExecutorch() is called before using any hooks:
Background Download Not Working
If background downloads aren’t working: iOS: VerifyUIBackgroundModes in Info.plist
Android: Check permissions in AndroidManifest.xml
New Architecture Issues
If you encounter architecture-related errors:- Verify
newArchEnabled=trueinandroid/gradle.properties - Verify
:fabric_enabled => trueinios/Podfile - Clean and rebuild both platforms
Example: Complete Chat Application
Here’s a complete chat application example:Next Steps
- Explore available models
- Learn about Performance Optimization
- Understand Memory Management
- Check the Troubleshooting Guide
- Learn about Custom Models