From d313e637f24a139114c62dd3a93ffa2b8bce819a Mon Sep 17 00:00:00 2001 From: DomanskiFilip Date: Wed, 3 Sep 2025 22:00:59 +0200 Subject: [PATCH 1/3] fix(cli): improve Android BuildTask.kt Windows executable detection - Fix Android build error on Windows when using nvm4w - Add robust fallback logic for Windows executable detection - Prevent 'node.exe.cmd' and 'Cannot find module' errors - Graceful fallback to cargo when Node.js detection fails Fixes #13892 --- .changes/fix-android-build-nvm4w-windows.md | 5 ++++ .../buildSrc/src/main/kotlin/BuildTask.kt | 29 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-android-build-nvm4w-windows.md diff --git a/.changes/fix-android-build-nvm4w-windows.md b/.changes/fix-android-build-nvm4w-windows.md new file mode 100644 index 000000000000..2fb4c95d6a09 --- /dev/null +++ b/.changes/fix-android-build-nvm4w-windows.md @@ -0,0 +1,5 @@ +--- +'tauri-cli': 'patch:bug' +--- + +Fix Android build error on Windows when using nvm4w (issue documented at #13892 [bug] [android] [windows] [cli] [build] Android Build Error: A problem occurred starting process 'command 'C:\nvm4w\nodejs\node.exe.cmd'' and Error: Cannot find module '...tauri' when using nvm4w). The BuildTask.kt template now includes robust fallback logic for Windows executable detection, preventing the "Cannot find module" and "node.exe.cmd" errors that occurred with nvm4w Node.js installations. The fix tries multiple Windows-specific fallbacks including .cmd, .bat extensions and cargo as a last resort. diff --git a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt index 8bbef994aab8..8951bd1f543a 100644 --- a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt +++ b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt @@ -21,7 +21,24 @@ open class BuildTask : DefaultTask() { runTauriCli(executable) } catch (e: Exception) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { - runTauriCli("$executable.cmd") + // Try different Windows-specific fallbacks + val fallbacks = listOf( + "$executable.cmd", + "$executable.bat", + "cargo.exe", + "cargo" + ) + + var lastException: Exception = e + for (fallback in fallbacks) { + try { + runTauriCli(fallback) + return + } catch (fallbackException: Exception) { + lastException = fallbackException + } + } + throw lastException } else { throw e; } @@ -32,7 +49,15 @@ open class BuildTask : DefaultTask() { val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null") val target = target ?: throw GradleException("target cannot be null") val release = release ?: throw GradleException("release cannot be null") - val args = listOf({{quote-and-join tauri-binary-args}}); + + val baseArgs = listOf({{quote-and-join tauri-binary-args}}); + + // If we're using cargo as a fallback, we need to prepend "tauri" to the args + val args = if (executable.contains("cargo")) { + listOf("tauri") + baseArgs + } else { + baseArgs + }.toMutableList() project.exec { workingDir(File(project.projectDir, rootDirRel)) From c37134b5feccc9614631fc4bbe845671d9c8a2c4 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 7 Oct 2025 14:33:53 -0300 Subject: [PATCH 2/3] strip extension from project, try exe/cmd/bat --- .changes/android-init-windows-unix.md | 6 ++++++ .changes/fix-android-build-nvm4w-windows.md | 3 ++- crates/tauri-cli/src/mobile/init.rs | 11 ++++++++++- .../android/buildSrc/src/main/kotlin/BuildTask.kt | 5 ++--- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .changes/android-init-windows-unix.md diff --git a/.changes/android-init-windows-unix.md b/.changes/android-init-windows-unix.md new file mode 100644 index 000000000000..e188ee5bd214 --- /dev/null +++ b/.changes/android-init-windows-unix.md @@ -0,0 +1,6 @@ +--- +'tauri-cli': 'patch:bug' +'@tauri-apps/cli': patch:bug +--- + +Strip Windows-only extensions from the binary path so an Android project initialized on Windows can be used on UNIX systems. diff --git a/.changes/fix-android-build-nvm4w-windows.md b/.changes/fix-android-build-nvm4w-windows.md index 2fb4c95d6a09..bbc706cde6ea 100644 --- a/.changes/fix-android-build-nvm4w-windows.md +++ b/.changes/fix-android-build-nvm4w-windows.md @@ -1,5 +1,6 @@ --- 'tauri-cli': 'patch:bug' +'@tauri-apps/cli': patch:bug --- -Fix Android build error on Windows when using nvm4w (issue documented at #13892 [bug] [android] [windows] [cli] [build] Android Build Error: A problem occurred starting process 'command 'C:\nvm4w\nodejs\node.exe.cmd'' and Error: Cannot find module '...tauri' when using nvm4w). The BuildTask.kt template now includes robust fallback logic for Windows executable detection, preventing the "Cannot find module" and "node.exe.cmd" errors that occurred with nvm4w Node.js installations. The fix tries multiple Windows-specific fallbacks including .cmd, .bat extensions and cargo as a last resort. +Enhance Android build script usage on Windows by attempting to run cmd, bat and exe formats. diff --git a/crates/tauri-cli/src/mobile/init.rs b/crates/tauri-cli/src/mobile/init.rs index cd5b99d0c734..2868cb6d8024 100644 --- a/crates/tauri-cli/src/mobile/init.rs +++ b/crates/tauri-cli/src/mobile/init.rs @@ -117,7 +117,16 @@ pub fn exec( build_args.push(target.command_name()); build_args.push(target.ide_build_script_name()); - map.insert("tauri-binary", binary.to_string_lossy()); + let mut binary = binary.to_string_lossy().to_string(); + if binary.ends_with(".exe") || binary.ends_with(".cmd") || binary.ends_with(".bat") { + // remove Windows-only extension + binary.pop(); + binary.pop(); + binary.pop(); + binary.pop(); + } + + map.insert("tauri-binary", binary); map.insert("tauri-binary-args", &build_args); map.insert("tauri-binary-args-str", build_args.join(" ")); diff --git a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt index 8951bd1f543a..5bcca59b01e2 100644 --- a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt +++ b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt @@ -21,12 +21,11 @@ open class BuildTask : DefaultTask() { runTauriCli(executable) } catch (e: Exception) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { - // Try different Windows-specific fallbacks + // Try different Windows-specific extensions val fallbacks = listOf( + "$executable.exe", "$executable.cmd", "$executable.bat", - "cargo.exe", - "cargo" ) var lastException: Exception = e From 53160c4bc53ce64d9797917365a6fec897ee6d38 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 7 Oct 2025 14:48:55 -0300 Subject: [PATCH 3/3] revert args --- .../android/buildSrc/src/main/kotlin/BuildTask.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt index 5bcca59b01e2..a0b4a1205a22 100644 --- a/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt +++ b/crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt @@ -48,15 +48,7 @@ open class BuildTask : DefaultTask() { val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null") val target = target ?: throw GradleException("target cannot be null") val release = release ?: throw GradleException("release cannot be null") - - val baseArgs = listOf({{quote-and-join tauri-binary-args}}); - - // If we're using cargo as a fallback, we need to prepend "tauri" to the args - val args = if (executable.contains("cargo")) { - listOf("tauri") + baseArgs - } else { - baseArgs - }.toMutableList() + val args = listOf({{quote-and-join tauri-binary-args}}); project.exec { workingDir(File(project.projectDir, rootDirRel))