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>
This commit is contained in:
DomanskiFilip 2025-10-07 18:25:49 +00:00 committed by GitHub
parent 3d6868d09c
commit 19fb6f7cb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 2 deletions

View File

@ -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.

View File

@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:bug'
'@tauri-apps/cli': patch:bug
---
Enhance Android build script usage on Windows by attempting to run cmd, bat and exe formats.

View File

@ -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(" "));

View File

@ -21,7 +21,23 @@ open class BuildTask : DefaultTask() {
runTauriCli(executable)
} catch (e: Exception) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
runTauriCli("$executable.cmd")
// Try different Windows-specific extensions
val fallbacks = listOf(
"$executable.exe",
"$executable.cmd",
"$executable.bat",
)
var lastException: Exception = e
for (fallback in fallbacks) {
try {
runTauriCli(fallback)
return
} catch (fallbackException: Exception) {
lastException = fallbackException
}
}
throw lastException
} else {
throw e;
}