Rafiq, my prayer-times and Qur'an app, opens one bundled SQLite database with expo-sqlite. Play Console's Crashes & ANRs page showed a native crash on one release: 4 events, 4 users, listed as three separate issues because each CPU architecture got its own row. They were one bug.
[libexpo-modules-core.so] facebook::jni::getHybridDataFromField
signal 6 (SIGABRT)
The backtrace had 66 frames. None of them were my code, and none named a database, a player or a file. PostHog had nothing either: abort() kills the process from native code, so no JavaScript error handler ever runs. If you only watch a JS error tracker, crashes like this never reach you. Play Console and App Store Connect are the only places they show up.
Open the issue, not the list row
The line that names the problem isn't on the Crashes & ANRs list. It's one click deeper, in the issue detail:
Abort message: JNI DETECTED ERROR IN APPLICATION: ...
That's ART's CheckJNI catching native code that used a JNI reference it shouldn't have. With that line, two frames in the backtrace become useful:
-
MethodMetadata::callSync: a synchronous native call from JS. -
convertSharedObject: the call's return value is a shared object (a native object with a JS wrapper).
I first blamed expo-audio, because audio was the last thing I'd shipped and "shared object" sounded like an audio player. That was wrong. Every constructor in expo-audio's AudioModule.kt builds a fresh instance, and a fresh shared object can't reach the crashing branch. The frame names the converter, not the module that called it. So the question was which module can return a shared object that already exists.
The branch that crashes
Here's convertSharedObject in expo-modules-core's JNIUtils.cpp, as it was when the crash happened:
int id = sharedObject->getId();
if (id != 0) {
return jsi::Value(rt, *jsiContext->getSharedObject(id)->cthis()->get());
}
// id == 0: a new object, register it and build its JS wrapper
An id of 0 means "new object, register it". A non-zero id means "this object is already registered, look up its JS wrapper". On the Kotlin side, JSIContext.getSharedObject(id) returns JavaScriptObject?. It can be null when:
- the runtime context is gone,
- a reload left a stale id behind in the registry, or
- the registry's weak handle on the JS wrapper was garbage collected.
The C++ called ->cthis() on that result without checking for null. Reading hybrid data off a null jobject is exactly what CheckJNI aborts on. That's getHybridDataFromField.
Who hands back an already-registered object
Only one module in the app returns an object that already exists: expo-sqlite. The NativeDatabase constructor in SQLiteModule.kt checks a connection cache first:
findCachedDatabase {
it.databasePath == databasePath &&
it.openOptions == options &&
!options.useNewConnection
}?.let { /* addRef() and return the cached, already-registered instance */ }
If a connection for the same path is still cached, JS gets the old object back with its non-zero id. That sends it down the lookup branch. If the JS wrapper died in the meantime, the process aborts.
The fix: useNewConnection, as a module-scoped constant
Look at the last condition in that cache check: !options.useNewConnection. With useNewConnection: true, the cache is skipped, the constructor always builds a fresh object with id 0, and the crashing branch can't be reached. Rafiq opens exactly one read-only database once, so it loses nothing by not sharing connections. On the JS side, the flag's only other effect is DevTools registration, which is dev-only.
// Module scope on purpose: see the next section.
const QURAN_DB_OPTIONS = { useNewConnection: true } as const
<SQLiteProvider databaseName="quran.db" options={QURAN_DB_OPTIONS} useSuspense>
Don't pass it as an inline object
My first instinct was options={{ useNewConnection: true }}. Reading expo-sqlite/build/hooks.js before writing it stopped me. SQLiteProvider has two comparisons of options, and they disagree:
- The component's
memocomparator usesdeepEqual(prevProps.options, nextProps.options). - The suspense cache a few lines further down uses
databaseInstance?.options === options, which compares by reference.
An inline object is a new reference on every remount, so the suspense cache misses. On a miss it does this:
promise = databaseInstance.promise.then((db) => {
db.closeAsync() // not awaited
// ...then reopens the same database
})
The close is fired and never awaited, so the reopen races it. That's the stale-registration window the crash needs. An inline literal would have triggered the bug on every remount on every device. A module-scoped constant keeps the same reference, so the cache hits and nothing closes.
When a library caches on an options object, check whether it compares by value or by reference. Two comparators in the same file don't have to agree.
What newer expo-modules-core does
The expo-modules-core I have installed now (58.0.30) checks the lookup:
auto jsObject = jsiContext->getSharedObject(id);
if (jsObject == nullptr) {
throw jsi::JSError(rt, "Cannot return shared object: its JavaScript instance is no longer available.");
}
So on current versions the same situation throws a JavaScript error you can catch, not a SIGABRT. If you see that message, the cause is the same: a module handed back a cached shared object whose JS wrapper is gone. I keep useNewConnection anyway. A catchable error is better than an abort, but the database still fails to open.
Checklist
- Native crash with no app frames: read the
Abort message:line in the Play Console issue detail. -
callSync+convertSharedObjectin the backtrace: look for a module that returns a cached shared object, not a new one. - expo-sqlite: open with
useNewConnection: truewhen you don't need connection sharing. - Pass
SQLiteProvideroptions as a module-scoped constant, never an inline literal. - After every release, read Play Console's crash page. A JS error tracker can't see native aborts.
Top comments (0)