I'm creating a simple app that uses data in a preloaded database from an assets folder ("../assets/worldEnglishBible.db" (4.8 MB). I'm utilizing expo-sqlite to query the data and expo-file-system to load the database so it can be used by expo-sqlite. The database loads and is fully accessible when tested on the Expo Go app; however, when I create a production build and run it on TestFlight the database fails to load fully (only loads 243 bytes, <1%).
Below is my code to load the database. The deleteDatabaseSQL function is used to for development, to delete the database and re-download it for testing.
import * as FileSystem from "expo-file-system";
import { Asset } from "expo-asset";
const downloadWEB = async (setDatabaseSize, setConsoleText) => {
const callback = (downloadProgress) => {
console.log(downloadProgress.totalBytesWritten);
setDatabaseSize(downloadProgress.totalBytesWritten);
};
//Download WEB database
const downloadResumableWEB = FileSystem.createDownloadResumable(
Asset.fromModule(require("../assets/worldEnglishBible.db")).uri,
FileSystem.documentDirectory + "SQLite/worldEnglishBible.db",
{},
callback
);
try {
await FileSystem.makeDirectoryAsync(
FileSystem.documentDirectory + "SQLite"
);
const { uri } = await downloadResumableWEB.downloadAsync();
console.log("Finished downloading to ", uri);
setConsoleText("Finished downloading to " + uri);
} catch (error) {
console.log(error.message);
setConsoleText(error.message);
}
};
const deleteDatabaseSQL = async (setDatabaseSize, setConsoleText) => {
try {
await FileSystem.deleteAsync(FileSystem.documentDirectory + "SQLite");
console.log("database deleted");
setConsoleText("database deleted");
setDatabaseSize(0);
} catch (error) {
console.log(error.message);
setConsoleText(error.message);
} finally {
}
};
export { downloadWEB, deleteDatabaseSQL };
Below is my metro.config.js file
const { getDefaultConfig } = require("expo/metro-config");
const config = getDefaultConfig(__dirname);
config.resolver.assetExts.push(
// Adds support for `.db` files for SQLite databases
"db"
);
module.exports = config;
Here is a screenshot from a development screen when my app is loaded on TestFlight. The highlighted portion is an AppContext state variable consoleText, set by setConsoleText.
Thank you!