onnxruntime
99e811d1 - [React Native] Add react-native.config.js and Expo plugin MainApplication patch to fix autolinking (#28266)

Commit
110 days ago
[React Native] Add react-native.config.js and Expo plugin MainApplication patch to fix autolinking (#28266) ## Summary This PR fixes the long-standing issue where `onnxruntime-react-native` requires manual native setup after installation, causing the `TypeError: Cannot read property 'install' of null` runtime crash. **Root cause:** The package shipped without a `react-native.config.js`, so the RN community CLI autolinking did not register `OnnxruntimePackage` on Android. For Expo users on the New Architecture, the existing `app.plugin.js` patched Gradle and the Podfile but never registered the package class in `MainApplication`. **Changes:** - **`react-native.config.js`** (new) — enables RN community autolinking for Android. With RN 0.74+ this covers both old and new architecture via the generated `PackageList.java`. No manual `settings.gradle` or `MainApplication` edits needed for bare RN. - **`app.plugin.js`** — adds a `withMainApplication` mod that idempotently inserts the `OnnxruntimePackage` import and registration into `MainApplication.kt`/`.java` during `expo prebuild`. Uses the same `mergeContents` tag pattern as the existing Gradle/Podfile mods, so it is safe to run multiple times. - **`package.json`** — includes `react-native.config.js` in the npm `files` array so it ships in the tarball. - **`README.md`** — documents that autolinking handles registration automatically and adds the Expo plugin usage snippet. ## Testing - Bare RN: `npx react-native config | jq '.dependencies["onnxruntime-react-native"]'` should show `packageImportPath` populated; `PackageList.java` should include `OnnxruntimePackage` after a Gradle sync. - Expo: `npx expo prebuild --clean` should produce a `MainApplication.kt` containing `import ai.onnxruntime.reactnative.OnnxruntimePackage` and `add(OnnxruntimePackage())`. Fixes #19510 See also #17773
Author
Parents
Loading