Skip to content

Commit be0cb0d

Browse files
authored
fix(cli): Honor a specified NDK version if set (#15344)
1 parent 9167826 commit be0cb0d

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

.changes/fix-ndk-home-not-honor.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:bug
3+
---
4+
5+
Fix NDK_HOME environment variable not honored when set

crates/tauri-cli/src/mobile/android/mod.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,27 @@ fn ensure_ndk(non_interactive: bool) -> Result<()> {
591591
.or_else(|| std::env::var_os("ANDROID_SDK_ROOT"))
592592
.map(PathBuf::from)
593593
.context("Failed to locate Android SDK")?;
594-
let mut installed_ndks = read_dir(android_home.join("ndk"))
595-
.map(|dir| {
596-
dir
597-
.into_iter()
598-
.flat_map(|e| e.ok().map(|e| e.path()))
599-
.collect::<Vec<_>>()
600-
})
601-
.unwrap_or_default();
594+
595+
// check NDK_HOME
596+
let mut installed_ndks = if let Some(ndk_home) = std::env::var_os("NDK_HOME") {
597+
let ndk_path = PathBuf::from(ndk_home);
598+
if ndk_path.is_dir() {
599+
vec![ndk_path]
600+
} else {
601+
crate::error::bail!(
602+
"Android NDK invalid. Make sure the NDK_HOME environment variable has correct value."
603+
);
604+
}
605+
} else {
606+
read_dir(android_home.join("ndk"))
607+
.map(|dir| {
608+
dir
609+
.into_iter()
610+
.flat_map(|e| e.ok().map(|e| e.path()))
611+
.collect::<Vec<_>>()
612+
})
613+
.unwrap_or_default()
614+
};
602615
installed_ndks.sort();
603616

604617
if let Some(ndk) = installed_ndks.last() {

0 commit comments

Comments
 (0)