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))