Fix VersionNumber usage in React Native Android build with major version validation (#27385)
### Description
Replaced `VersionNumber.parse()` with integer comparison on both major
and minor versions, including validation for version format and future
React Native 1.0+ compatibility:
```gradle
// Before - fails in dependencies block
if (VersionNumber.parse(REACT_NATIVE_VERSION) < VersionNumber.parse("0.71")) {
extractLibs "com.facebook.fbjni:fbjni:+:headers"
extractLibs "com.facebook.fbjni:fbjni:+"
}
// After - extracts and validates major and minor versions
def versionParts = REACT_NATIVE_VERSION.split("\\.")
if (versionParts.length < 2) {
throw new GradleException("Invalid React Native version format: ${REACT_NATIVE_VERSION}. Expected format: major.minor[.patch]")
}
def REACT_NATIVE_MAJOR_VERSION = versionParts[0].toInteger()
def REACT_NATIVE_MINOR_VERSION = versionParts[1].toInteger()
// For fbjni dependencies
if (REACT_NATIVE_MAJOR_VERSION == 0 && REACT_NATIVE_MINOR_VERSION < 71) {
extractLibs "com.facebook.fbjni:fbjni:+:headers"
extractLibs "com.facebook.fbjni:fbjni:+"
}
// For c++_shared configuration
if (REACT_NATIVE_MAJOR_VERSION > 0 || REACT_NATIVE_MINOR_VERSION >= 71) {
// Use c++_shared
}
```
**Version Logic:**
- **React Native 0.70 and earlier**: Old behavior (no c++_shared,
include fbjni dependencies)
- **React Native 0.71+**: New behavior (use c++_shared, no fbjni
dependencies)
- **React Native 1.0+ (future)**: New behavior (use c++_shared, no fbjni
dependencies)
**Additional improvements:**
- Added version format validation to prevent runtime errors on malformed
versions
- Error message accurately reflects that patch version is optional
(`major.minor[.patch]`)
- Used clearer condition `REACT_NATIVE_MAJOR_VERSION > 0` for better
code clarity
- Ensures correct behavior when React Native eventually releases version
1.0+
### Motivation and Context
`VersionNumber` is unavailable in dependencies block context, causing:
```
Could not get unknown property 'VersionNumber' for object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
```
Integer comparison with major version validation is simpler,
context-independent, and future-proof for React Native 1.0+ releases.
The patch version is optional since only major and minor versions are
used in the comparison logic.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Failing to build project</issue_title>
> <issue_description>### Describe the issue
>
> This code in the build.gradle was causing the build to fail:
>
> if (VersionNumber.parse(REACT_NATIVE_VERSION) <
VersionNumber.parse("0.71")) {
> extractLibs "com.facebook.fbjni:fbjni:+:headers"
> extractLibs "com.facebook.fbjni:fbjni:+"
> }
>
> I had to comment it out for it to work.
>
> ### Urgency
>
> Not urgent
> ### Target platform
>
> React Native
>
> ### Build script
>
> npm run build
>
> ### Error / output
>
> A problem occurred evaluating project ':onnxruntime-react-native'. >
Could not get unknown property 'VersionNumber' for object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
>
> ### Visual Studio Version
>
> 1.109.0
>
> ### GCC / Compiler Version
>
> _No response_</issue_description>
>
> <agent_instructions>Analyze why usage of VersionNumber in
https://github.com/microsoft/onnxruntime/blob/cd7e3391206e7ef65980543bb2c057304a5731f5/js/react_native/android/build.gradle#L250-L253
may not be working</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes microsoft/onnxruntime#27281
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: skottmckay <979079+skottmckay@users.noreply.github.com>
Co-authored-by: edgchen1 <18449977+edgchen1@users.noreply.github.com>