During development of Zyke App for the Zyke Band we ran in these issues with onnxruntime-react-native.
onnxruntime-react-native 1.24.3 failed on Android (in our case with Expo 55) with two issues:
- Gradle 9 build failure —
VersionNumberclass was removed in Gradle 9, breakingbuild.gradleline 250 (Expo 55 uses React-Native 0.83.x, so this check is not required) - Runtime crash —
NativeModules.Onnxruntimewasnull, causingCannot read property 'install' of nullat startup
The library's build.gradle uses VersionNumber.parse() (from org.gradle.util.VersionNumber) which was deprecated in Gradle 7.1 and removed in Gradle 9. The check was only relevant for React Native < 0.71 — dead code for modern RN versions.
onnxruntime-react-native uses the legacy ReactPackage pattern (OnnxruntimePackage.java) which Expo's autolinking does not pick up. The Gradle dependency was linked, but the Java package was never registered in PackageList — so NativeModules.Onnxruntime was null at runtime.
Reference: microsoft/onnxruntime#19510
Removed the dead VersionNumber block:
- if (VersionNumber.parse(REACT_NATIVE_VERSION) < VersionNumber.parse("0.71")) {
- extractLibs "com.facebook.fbjni:fbjni:+:headers"
- extractLibs "com.facebook.fbjni:fbjni:+"
- }Guarded Module.install() and added a silent stub fallback for background JS contexts where native modules are unavailable:
-if (typeof globalThis.OrtApi === 'undefined') {
+if (typeof globalThis.OrtApi === 'undefined' && Module != null) {
Module.install();
}When Module is null, exports a no-op stub ({ listSupportedBackends: () => [] }) instead of a throwing Proxy.
Created a custom Expo config plugin that injects OnnxruntimePackage into MainApplication.kt during prebuild — solving the autolinking gap:
import ai.onnxruntime.reactnative.OnnxruntimePackage
// ...
PackageList(this).packages.apply {
add(OnnxruntimePackage())
}Replaced ['onnxruntime-react-native'] (library has no plugin) with ['./plugins/with-onnxruntime'].
| File | Change |
|---|---|
patches/onnxruntime-react-native+1.24.3.patch |
Gradle 9 compat + background JS guard |
plugins/with-onnxruntime.js |
New Expo config plugin for native module registration |
app.config.ts |
Updated plugin reference |