A comprehensive guide to integrating SQLite extensions in Expo and React Native applications using OP-SQLite.
Before setting up SQLite extensions, you'll need to create and initialize your 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/todoappSince SQLite extensions require native code, you must initialize your project:
cd MyApp
npx expo prebuildImportant: Run
npx expo prebuildafter any changes to native dependencies or extension files.
- 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
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.
- Go to sqlite-sync releases
- Download the
cloudsync-apple-xcframework-*.zip - Extract
CloudSync.xcframework
-
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
npm install @op-engineering/op-sqlite
npx pod-installnpx expo install @op-engineering/op-sqlite
npx expo prebuildimport { getDylibPath, open } from "@op-engineering/op-sqlite";
import { Platform } from 'react-native';
// Open database connection
const db = open({ name: 'to-do-app' });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;
}
};For comprehensive usage examples and best practices, refer to the official Expo to-do-app example.
Note: This setup requires native code generation. Make sure to run npx expo prebuild after installing OP-SQLite and adding the extension files.