SQLite Extensions in Expo/React Native
September 18, 2025 Β· View on GitHub
A comprehensive guide to integrating SQLite extensions in Expo and React Native applications using OP-SQLite.
π Getting Started
Before setting up SQLite extensions, you'll need to create and initialize your project:
Create a New Expo Project
# Create a new project
npx create-expo-app MyApp
# Or use our pre-configured template with SQLite extensions
npx create-expo-app MyApp --template @sqliteai/todoapp
Initialize for Native Code
Since SQLite extensions require native code, you must initialize your project:
cd MyApp
npx expo prebuild
Important: Run
npx expo prebuildafter any changes to native dependencies or extension files.
π€ Android Setup
Step 1: Download Android Extension
- Go to sqlite-sync releases
- Download your preferred .zip architecture releases:
- arm64-v8a - Modern 64-bit ARM devices (recommended for most users)
- x86_64 - 64-bit x86 emulators and Intel-based devices
Step 2: Place Extension Files
Extract the .so files in the following directory structure:
/android
/app
/src
/main
/jniLibs
/arm64-v8a
cloudsync.so
/x86_64
cloudsync.so
Note: Create the
jniLibsdirectory structure if it doesn't exist.
π iOS Setup
Step 1: Download iOS Extension
- Go to sqlite-sync releases
- Download the
cloudsync-apple-xcframework-*.zip - Extract
CloudSync.xcframework
Step 2: Add Framework to Project
-
Place the framework in your project:
/ios /[app-name] /Frameworks /CloudSync.xcframework -
Open Xcode:
- Open Existing Project β Select your Expo app's
iosfolder - Click on your app name (top left, with Xcode logo)
- Open Existing Project β Select your Expo app's
-
Configure Target:
- Go to Targets β [app-name] β General tab
- Scroll down to "Frameworks, Libraries, and Embedded Content"
- Click "+" β "Add Otherβ¦" β "Add Filesβ¦"
- Select
/ios/[app-name]/Frameworks/CloudSync.xcframework
-
Set Embed Options:
- Ensure the "Embed" column shows either:
- "Embed & Sign" (recommended)
- "Embed Without Signing"
- Ensure the "Embed" column shows either:
-
Verify Build Phases:
- Go to "Build Phases" tab
- Check that "Embed Frameworks" section contains CloudSync
-
Close Xcode
π¦ Install OP-SQLite
For React Native:
npm install @op-engineering/op-sqlite
npx pod-install
For Expo:
npx expo install @op-engineering/op-sqlite
npx expo prebuild
π» Implementation
Basic Setup
import { getDylibPath, open } from "@op-engineering/op-sqlite";
import { Platform } from 'react-native';
// Open database connection
const db = open({ name: 'to-do-app' });
Load Extension
const loadCloudSyncExtension = async () => {
let extensionPath;
console.log('Loading CloudSync extension...');
try {
if (Platform.OS === "ios") {
extensionPath = getDylibPath("ai.sqlite.cloudsync", "CloudSync");
} else {
extensionPath = 'cloudsync';
}
// Load the extension
db.loadExtension(extensionPath);
// Verify extension loaded successfully
const version = await db.execute('SELECT cloudsync_version();');
console.log(`CloudSync extension loaded successfully, version: ${version.rows[0]['cloudsync_version()']}`);
return true;
} catch (error) {
console.error('Error loading CloudSync extension:', error);
return false;
}
};
π Usage Examples
For comprehensive usage examples and best practices, refer to the official Expo to-do-app example.
π Additional Resources
Note: This setup requires native code generation. Make sure to run npx expo prebuild after installing OP-SQLite and adding the extension files.