Skip to content

Commit 39df2c9

Browse files
fix(cli/android): fallback to ${program}.cmd (#6576)
* fix(cli/android): fallback to `${program}.cmd` * cleanup [skip ci] * revert variable to tauri-binary [skip ci] --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 6e3e4c2 commit 39df2c9

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

.changes/pnpm-android.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'cli.rs': 'patch'
3+
---
4+
5+
Fix `tauri anroid build/dev` crashing when used with standalone `pnpm` executable on Windows.

tooling/cli/src/mobile/init.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ pub fn exec(
121121
let binary_path = PathBuf::from(&binary);
122122
let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
123123
let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
124-
let mut is_npm = false;
125124
if r.is_match(&bin_stem) {
126125
if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
127-
is_npm = true;
128126
let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
129127
binary = if manager_stem == "npm-cli" {
130128
"npm".into()
@@ -144,20 +142,6 @@ pub fn exec(
144142
}
145143
}
146144
}
147-
if is_npm {
148-
map.insert(
149-
"executable",
150-
format!(
151-
r#"if (Os.isFamily(Os.FAMILY_WINDOWS)) {{ """{binary}.cmd""" }} else {{ """{binary}""" }}"#,
152-
binary = binary.to_string_lossy()
153-
),
154-
);
155-
} else {
156-
map.insert(
157-
"executable",
158-
format!(r#""""{}""""#, binary.to_string_lossy()),
159-
);
160-
}
161145

162146
map.insert("tauri-binary", binary.to_string_lossy());
163147
map.insert("tauri-binary-args", &build_args);

tooling/cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,28 @@ open class BuildTask : DefaultTask() {
2222

2323
@TaskAction
2424
fun build() {
25+
val executable = """{{tauri-binary}}""";
26+
try {
27+
runTauriCli(executable)
28+
} catch (e: Exception){
29+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
30+
runTauriCli("$executable.cmd")
31+
} else {
32+
throw e;
33+
}
34+
}
35+
}
36+
37+
fun runTauriCli(executable: String) {
2538
val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null")
2639
val target = target ?: throw GradleException("target cannot be null")
2740
val release = release ?: throw GradleException("release cannot be null")
41+
val args = listOf({{quote-and-join tauri-binary-args}});
42+
2843
project.exec {
2944
workingDir(File(project.projectDir, rootDirRel.path))
30-
executable({{executable}})
31-
args(listOf({{quote-and-join tauri-binary-args}}))
45+
executable(executable)
46+
args(args)
3247
if (project.logger.isEnabled(LogLevel.DEBUG)) {
3348
args("-vv")
3449
} else if (project.logger.isEnabled(LogLevel.INFO)) {
@@ -40,5 +55,4 @@ open class BuildTask : DefaultTask() {
4055
args(listOf("--target", target))
4156
}.assertNormalExitValue()
4257
}
43-
}
44-
58+
}

0 commit comments

Comments
 (0)