This guide walks you through setting up React Native ExecuTorch in an Expo project, from installation to running your first AI model.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
- Expo CLI installed (
npm install -g expo-cli) - iOS 17.0+ or Android 13+ device/emulator
- 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 Expo Project
Create a New Project
Update Existing Project
Ensure you’re on a compatible Expo SDK version:Step 2: Install Dependencies
Install React Native ExecuTorch and Expo resource fetcher:Step 3: Initialize Resource Fetcher
Create or update your app’s entry point to initialize the ExpoResourceFetcher.For Expo Router Projects
Create or updateapp/_layout.tsx:
For Standard Expo Projects
UpdateApp.tsx or App.js:
Step 4: Configure for New Architecture
React Native ExecuTorch requires the New Architecture. Update yourapp.json:
Step 5: Run Your First Model
Create a simple component to test model loading:Step 6: Build and Run
iOS
- Install CocoaPods dependencies
- Build the native iOS app
- Launch on a connected device or simulator
Android
- Install Gradle dependencies
- Build the native Android app
- Launch on a connected device or emulator
Using ExpoResourceFetcher Features
Loading Models from Different Sources
Managing Downloads
Managing Storage
Working with Expo Assets
For small models (< 512MB), use Expo’s asset system:Configure app.json
Load Assets
Common Expo Configuration
Increase Memory Limit (Android)
For Android builds, you may need to increase heap size. Create or updateandroid/gradle.properties:
Configure Permissions
Updateapp.json if your app needs specific permissions:
File Storage Location
ExpoResourceFetcher stores files in:- iOS:
{DocumentDirectory}/react-native-executorch/ - Android:
{DocumentDirectory}/react-native-executorch/
Troubleshooting
Resource Fetcher Not Initialized
Error:ResourceFetcherAdapterNotInitialized
Solution: Ensure initExecutorch() is called before using any hooks:
New Architecture Not Enabled
If you see architecture-related errors, verifyapp.json configuration and rebuild:
Download Failures
If downloads fail:- Check network connectivity
- Verify URL is accessible
- Check available storage space
- Try with a smaller model first
Model Not Loading
- Check download progress:
llm.downloadProgress - Check for errors:
llm.error - Verify model file is valid
.pteformat - Check device has sufficient RAM (see Memory Management)
Example: Complete Chat App
Here’s a complete example of a chat app with Expo:Next Steps
- Explore available models on HuggingFace
- Learn about Performance Optimization
- Understand Memory Management
- Check the Troubleshooting Guide
- Learn about Custom Models