From 20c0fcf1f433c75e783379335577eb1987a212e8 Mon Sep 17 00:00:00 2001 From: yecong Date: Thu, 12 Nov 2026 16:11:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=BA=94=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=B9=B6=E6=8E=92=E9=99=A4=20SDK=20=E4=BA=A4=E4=BB=98?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + android/app/build.gradle | 3 +++ android/node.gradle | 48 ++++++++++++++++++++++++++++++++++++++++ android/settings.gradle | 8 ++++++- package.json | 4 ++-- src/HomeScreen.tsx | 4 ++-- 6 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 android/node.gradle diff --git a/.gitignore b/.gitignore index ad0a611..9334586 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,4 @@ yarn-error.log # Local SDK workspace sdk/ +sdk-repair/ diff --git a/android/app/build.gradle b/android/app/build.gradle index 973556d..41a1b61 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -2,6 +2,8 @@ apply plugin: "com.android.application" apply plugin: "org.jetbrains.kotlin.android" apply plugin: "com.facebook.react" +apply from: rootProject.file("node.gradle") + /** * This is the configuration block to customize your React Native Android app. * By default you don't need to apply any configuration, just uncomment the lines you need. @@ -26,6 +28,7 @@ react { /* Bundling */ // A list containing the node command and its flags. Default is just 'node'. // nodeExecutableAndArgs = ["node"] + nodeExecutableAndArgs = [resolveNodeExecutable()] // // The command to run when bundling. By default is 'bundle' // bundleCommand = "ram-bundle" diff --git a/android/node.gradle b/android/node.gradle new file mode 100644 index 0000000..8a94923 --- /dev/null +++ b/android/node.gradle @@ -0,0 +1,48 @@ +def parseNodeVersion = { String value -> + value.replaceFirst("^v", "") + .tokenize(".") + .collect { part -> + def matcher = part =~ /\d+/ + matcher.find() ? matcher.group().toInteger() : 0 + } +} + +ext.resolveNodeExecutable = { + def fromEnv = System.getenv("NODE_BINARY") + if (fromEnv != null && !fromEnv.trim().isEmpty()) { + return fromEnv.trim() + } + + def home = System.getProperty("user.home") + def candidates = [] + def nvmVersionsDir = new File(home, ".nvm/versions/node") + + if (nvmVersionsDir.isDirectory()) { + def versionDirs = nvmVersionsDir.listFiles()?.findAll { + new File(it, "bin/node").canExecute() + } ?: [] + + versionDirs.sort { a, b -> + def aVersion = parseNodeVersion(a.name) + def bVersion = parseNodeVersion(b.name) + for (int i = 0; i < Math.max(aVersion.size(), bVersion.size()); i++) { + def aPart = i < aVersion.size() ? aVersion[i] : 0 + def bPart = i < bVersion.size() ? bVersion[i] : 0 + if (aPart != bPart) { + return bPart <=> aPart + } + } + return b.name <=> a.name + }.each { + candidates.add(new File(it, "bin/node").absolutePath) + } + } + + candidates.addAll([ + "${home}/.nvm/current/bin/node", + "/opt/homebrew/bin/node", + "/usr/local/bin/node" + ]) + + return candidates.find { new File(it).canExecute() } ?: "node" +} diff --git a/android/settings.gradle b/android/settings.gradle index 23d963a..fc05df9 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,6 +1,12 @@ pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } plugins { id("com.facebook.react.settings") } -extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } +apply from: new File(settingsDir, "node.gradle") + +def nodeExecutable = resolveNodeExecutable() +def reactNativeCli = new File(settingsDir, "../node_modules/@react-native-community/cli/build/bin.js") +extensions.configure(com.facebook.react.ReactSettingsExtension) { ex -> + ex.autolinkLibrariesFromCommand([nodeExecutable, reactNativeCli.absolutePath, "config"]) +} rootProject.name = 'dfuapp' include ':app' includeBuild('../node_modules/@react-native/gradle-plugin') diff --git a/package.json b/package.json index 8e77eb5..2db0528 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "private": true, "scripts": { "android": "react-native run-android", - "clean-a": "cd android && gradlew clean", + "clean-a": "cd android && ./gradlew clean", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest", - "build-a": "set NODE_OPTIONS=--openssl-legacy-provider && cd android&&gradlew assembleRelease" + "build-a": "cd android && ./gradlew assembleRelease" }, "dependencies": { "@react-native-async-storage/async-storage": "^2.2.0", diff --git a/src/HomeScreen.tsx b/src/HomeScreen.tsx index 16c2ee1..9f7455c 100644 --- a/src/HomeScreen.tsx +++ b/src/HomeScreen.tsx @@ -95,9 +95,9 @@ export default function HomeScreen({ navigation }: Props) { navigation.navigate("ScanScreen2")}> {t("home.paddle")} - {/* navigation.navigate("ScanScreen3")}> + navigation.navigate("ScanScreen3")}> {t("home.T5trainer")} - */} +