[React Native] Add react-native.config.js and Expo plugin MainApplication patch to fix autolinking#28266
Merged
guschmue merged 2 commits intomicrosoft:mainfrom Apr 30, 2026
Merged
[React Native] Add react-native.config.js and Expo plugin MainApplication patch to fix autolinking#28266guschmue merged 2 commits intomicrosoft:mainfrom
guschmue merged 2 commits intomicrosoft:mainfrom
Conversation
… to fix autolinking
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to fix Android (and Expo prebuild/New Architecture) autolinking for onnxruntime-react-native to avoid runtime crashes caused by the native package not being registered.
Changes:
- Add
react-native.config.jsto explicitly provide Android autolinking metadata (packageImportPath/packageInstance). - Extend the Expo config plugin (
app.plugin.js) to patchMainApplication.kt/.javawithOnnxruntimePackageimport + registration. - Ensure the new config file is published (package
filesarray) and document expected setup inREADME.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| js/react_native/react-native.config.js | Adds explicit RN CLI autolinking configuration for Android. |
| js/react_native/app.plugin.js | Adds Expo prebuild MainApplication patching to register OnnxruntimePackage. |
| js/react_native/package.json | Ships react-native.config.js in the published package. |
| js/react_native/README.md | Documents autolinking behavior and Expo plugin usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@dccarmo please accept the license cla. I hope this gets merged soon |
Contributor
Author
@microsoft-github-policy-service agree |
guschmue
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the long-standing issue where
onnxruntime-react-nativerequiresmanual native setup after installation, causing the
TypeError: Cannot read property 'install' of nullruntime crash.Root cause: The package shipped without a
react-native.config.js, so the RNcommunity CLI autolinking did not register
OnnxruntimePackageon Android. For Expousers on the New Architecture, the existing
app.plugin.jspatched Gradle and thePodfile 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 manualsettings.gradleorMainApplicationedits neededfor bare RN.
app.plugin.js— adds awithMainApplicationmod that idempotently insertsthe
OnnxruntimePackageimport and registration intoMainApplication.kt/.javaduring
expo prebuild. Uses the samemergeContentstag pattern as the existingGradle/Podfile mods, so it is safe to run multiple times.
package.json— includesreact-native.config.jsin the npmfilesarray soit ships in the tarball.
README.md— documents that autolinking handles registration automatically andadds the Expo plugin usage snippet.
Testing
npx react-native config | jq '.dependencies["onnxruntime-react-native"]'should show
packageImportPathpopulated;PackageList.javashould includeOnnxruntimePackageafter a Gradle sync.npx expo prebuild --cleanshould produce aMainApplication.ktcontainingimport ai.onnxruntime.reactnative.OnnxruntimePackageandadd(OnnxruntimePackage()).Fixes #19510
See also #17773