Skip to content

Commit 19fb6f7

Browse files
fix(cli): improve Android BuildTask.kt Windows executable detection for nvm4w Fixes #13892 (#14146)
* 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 * strip extension from project, try exe/cmd/bat * revert args --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 3d6868d commit 19fb6f7

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'patch:bug'
3+
'@tauri-apps/cli': patch:bug
4+
---
5+
6+
Strip Windows-only extensions from the binary path so an Android project initialized on Windows can be used on UNIX systems.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'patch:bug'
3+
'@tauri-apps/cli': patch:bug
4+
---
5+
6+
Enhance Android build script usage on Windows by attempting to run cmd, bat and exe formats.

crates/tauri-cli/src/mobile/init.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ pub fn exec(
117117
build_args.push(target.command_name());
118118
build_args.push(target.ide_build_script_name());
119119

120-
map.insert("tauri-binary", binary.to_string_lossy());
120+
let mut binary = binary.to_string_lossy().to_string();
121+
if binary.ends_with(".exe") || binary.ends_with(".cmd") || binary.ends_with(".bat") {
122+
// remove Windows-only extension
123+
binary.pop();
124+
binary.pop();
125+
binary.pop();
126+
binary.pop();
127+
}
128+
129+
map.insert("tauri-binary", binary);
121130
map.insert("tauri-binary-args", &build_args);
122131
map.insert("tauri-binary-args-str", build_args.join(" "));
123132

crates/tauri-cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ open class BuildTask : DefaultTask() {
2121
runTauriCli(executable)
2222
} catch (e: Exception) {
2323
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
24-
runTauriCli("$executable.cmd")
24+
// Try different Windows-specific extensions
25+
val fallbacks = listOf(
26+
"$executable.exe",
27+
"$executable.cmd",
28+
"$executable.bat",
29+
)
30+
31+
var lastException: Exception = e
32+
for (fallback in fallbacks) {
33+
try {
34+
runTauriCli(fallback)
35+
return
36+
} catch (fallbackException: Exception) {
37+
lastException = fallbackException
38+
}
39+
}
40+
throw lastException
2541
} else {
2642
throw e;
2743
}

0 commit comments

Comments
 (0)