Skip to content

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

Merged
guschmue merged 2 commits intomicrosoft:mainfrom
dccarmo:main
Apr 30, 2026
Merged

[React Native] Add react-native.config.js and Expo plugin MainApplication patch to fix autolinking#28266
guschmue merged 2 commits intomicrosoft:mainfrom
dccarmo:main

Conversation

@dccarmo
Copy link
Copy Markdown
Contributor

@dccarmo dccarmo commented Apr 29, 2026

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js to explicitly provide Android autolinking metadata (packageImportPath / packageInstance).
  • Extend the Expo config plugin (app.plugin.js) to patch MainApplication.kt/.java with OnnxruntimePackage import + registration.
  • Ensure the new config file is published (package files array) and document expected setup in README.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.

Comment thread js/react_native/app.plugin.js Outdated
@dewana-sl
Copy link
Copy Markdown

@dccarmo please accept the license cla. I hope this gets merged soon

@dccarmo
Copy link
Copy Markdown
Contributor Author

dccarmo commented Apr 29, 2026

@dccarmo please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@guschmue guschmue merged commit 99e811d into microsoft:main Apr 30, 2026
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Build] Cannot read property 'install' of null with onnxruntime-react-native imported

4 participants