mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
### Description <!-- Describe your changes. --> Upgrading RN to 0.71.19, including Android and iOS changes.. This PR also include the E2E test changes. Used React-Native upgrade [helper](https://react-native-community.github.io/upgrade-helper/?from=0.70.15&to=0.71.19&package=onnxruntime-android&name=onnxruntime) as the reference. ### Motivation and Context Need newer RN version to fix S360 work items.
243 lines
No EOL
7.2 KiB
Groovy
243 lines
No EOL
7.2 KiB
Groovy
import java.nio.file.Paths
|
|
|
|
buildscript {
|
|
repositories {
|
|
google()
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
classpath 'com.android.tools.build:gradle:7.4.2'
|
|
// noinspection DifferentKotlinGradleVersion
|
|
}
|
|
}
|
|
|
|
apply plugin: 'com.android.library'
|
|
|
|
def getExtOrDefault(name) {
|
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['OnnxruntimeModule_' + name]
|
|
}
|
|
|
|
def getExtOrIntegerDefault(name) {
|
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['OnnxruntimeModule_' + name]).toInteger()
|
|
}
|
|
|
|
def reactNativeArchitectures() {
|
|
def value = project.getProperties().get("reactNativeArchitectures")
|
|
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
}
|
|
|
|
def resolveBuildType() {
|
|
Gradle gradle = getGradle()
|
|
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
|
|
return tskReqStr.contains('Release') ? 'release' : 'debug'
|
|
}
|
|
|
|
static def findNodeModules(baseDir) {
|
|
def basePath = baseDir.toPath().normalize()
|
|
while (basePath) {
|
|
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
|
|
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
|
|
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
|
|
return nodeModulesPath.toString()
|
|
}
|
|
basePath = basePath.getParent()
|
|
}
|
|
throw new GradleException("onnxruntime-react-native: Failed to find node_modules/ path!")
|
|
}
|
|
|
|
def nodeModules = findNodeModules(projectDir);
|
|
|
|
def checkIfOrtExtensionsEnabled() {
|
|
// locate user's project dir
|
|
def reactnativeRootDir = project.rootDir.parentFile
|
|
// get package.json file in root directory
|
|
def packageJsonFile = new File(reactnativeRootDir, 'package.json')
|
|
// read field 'onnxruntimeExtensionsEnabled'
|
|
if (packageJsonFile.exists()) {
|
|
def packageJsonContents = packageJsonFile.getText()
|
|
def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonContents)
|
|
return packageJson.onnxruntimeExtensionsEnabled == "true"
|
|
} else {
|
|
logger.warn("Could not find package.json file in the expected directory: ${reactnativeRootDir}. ONNX Runtime Extensions will not be enabled.")
|
|
}
|
|
return false
|
|
}
|
|
|
|
boolean ortExtensionsEnabled = checkIfOrtExtensionsEnabled()
|
|
|
|
def REACT_NATIVE_VERSION = ['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()
|
|
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
|
|
android {
|
|
// This is needed by the new AndroidManifestNew.xml
|
|
namespace "ai.onnxruntime.reactnative"
|
|
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
buildToolsVersion getExtOrDefault('buildToolsVersion')
|
|
defaultConfig {
|
|
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
versionCode 1
|
|
versionName "1.0"
|
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
externalNativeBuild {
|
|
cmake {
|
|
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
|
|
if (REACT_NATIVE_MINOR_VERSION >= 71) {
|
|
// fabricjni required c++_shared
|
|
arguments "-DANDROID_STL=c++_shared", "-DNODE_MODULES_DIR=${nodeModules}", "-DORT_EXTENSIONS_ENABLED=${ortExtensionsEnabled}"
|
|
} else {
|
|
arguments "-DNODE_MODULES_DIR=${nodeModules}", "-DORT_EXTENSIONS_ENABLED=${ortExtensionsEnabled}"
|
|
}
|
|
abiFilters (*reactNativeArchitectures())
|
|
}
|
|
}
|
|
}
|
|
|
|
if (rootProject.hasProperty("ndkPath")) {
|
|
ndkPath rootProject.ext.ndkPath
|
|
}
|
|
if (rootProject.hasProperty("ndkVersion")) {
|
|
ndkVersion rootProject.ext.ndkVersion
|
|
}
|
|
|
|
buildFeatures {
|
|
prefab true
|
|
}
|
|
|
|
externalNativeBuild {
|
|
cmake {
|
|
path "CMakeLists.txt"
|
|
}
|
|
}
|
|
|
|
packagingOptions {
|
|
pickFirst '**/libc++_shared.so'
|
|
pickFirst '**/libfbjni.so'
|
|
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
|
|
excludes = [
|
|
"META-INF",
|
|
"META-INF/**",
|
|
"**/libjsi.so",
|
|
]
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled false
|
|
}
|
|
}
|
|
lintOptions {
|
|
disable 'GradleCompatible'
|
|
}
|
|
compileOptions {
|
|
sourceCompatibility JavaVersion.VERSION_17
|
|
targetCompatibility JavaVersion.VERSION_17
|
|
}
|
|
|
|
sourceSets {
|
|
main {
|
|
java.srcDirs = ['src/main/java/']
|
|
// A tricky situation where iOS still uses the AndroidManifest.xml file, but the Android use AndroidManifestNew.xml
|
|
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
if (ortExtensionsEnabled) {
|
|
java.exclude '**/OnnxruntimeExtensionsDisabled.java'
|
|
} else {
|
|
java.exclude '**/OnnxruntimeExtensionsEnabled.java'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
google()
|
|
|
|
def found = false
|
|
def defaultDir = null
|
|
def androidSourcesName = 'React Native sources'
|
|
|
|
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
} else {
|
|
defaultDir = new File(
|
|
projectDir,
|
|
'/../../../node_modules/react-native/android'
|
|
)
|
|
}
|
|
|
|
if (defaultDir.exists()) {
|
|
maven {
|
|
url defaultDir.toString()
|
|
name androidSourcesName
|
|
}
|
|
|
|
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
found = true
|
|
} else {
|
|
def parentDir = rootProject.projectDir
|
|
|
|
1.upto(5, {
|
|
if (found) return true
|
|
parentDir = parentDir.parentFile
|
|
|
|
def androidSourcesDir = new File(
|
|
parentDir,
|
|
'node_modules/react-native'
|
|
)
|
|
|
|
def androidPrebuiltBinaryDir = new File(
|
|
parentDir,
|
|
'node_modules/react-native/android'
|
|
)
|
|
|
|
if (androidPrebuiltBinaryDir.exists()) {
|
|
maven {
|
|
url androidPrebuiltBinaryDir.toString()
|
|
name androidSourcesName
|
|
}
|
|
|
|
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
found = true
|
|
} else if (androidSourcesDir.exists()) {
|
|
maven {
|
|
url androidSourcesDir.toString()
|
|
name androidSourcesName
|
|
}
|
|
|
|
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
found = true
|
|
}
|
|
})
|
|
}
|
|
|
|
if (!found) {
|
|
throw new GradleException(
|
|
"${project.name}: unable to locate React Native android sources. " +
|
|
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
)
|
|
}
|
|
|
|
flatDir {
|
|
dir 'libs'
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
//noinspection GradleDynamicVersion
|
|
implementation "com.facebook.react:react-android:"+ REACT_NATIVE_VERSION
|
|
api "org.mockito:mockito-core:2.28.2"
|
|
|
|
androidTestImplementation "androidx.test:runner:1.5.2"
|
|
androidTestImplementation "androidx.test:rules:1.5.0"
|
|
implementation "junit:junit:4.12"
|
|
|
|
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline-extended:2.28.1"
|
|
|
|
implementation "com.microsoft.onnxruntime:onnxruntime-android:latest.integration@aar"
|
|
|
|
// By default it will just include onnxruntime full aar package
|
|
if (ortExtensionsEnabled) {
|
|
implementation "com.microsoft.onnxruntime:onnxruntime-extensions-android:latest.integration@aar"
|
|
}
|
|
} |