tauri: [bug] running `tauri android init` returns `NDK_HOME` environment variable isn't set, but the NDK is installed
Describe the bug
After following the prerequisites doc to the letter, installing Android Studio and downloading all the latest SDKs and NDKs, I’m still getting this error when running tauri android init:
action request: to initialize Android environment; Android support won't be usable until you
fix the issue below and re-run `tauri android init`!
Have you installed the NDK? The `NDK_HOME` environment variable isn't set, and is
required: environment variable not found
What can be causing this to KEEP happening? This results in Android Studio reporting Error running 'app' Default Activity not found after running tauri android dev
Reproduction
No response
Expected behavior
Tauri should be able to detect the installed NDK
Full tauri info output
action request: to initialize Android environment; Android support won't be usable until you
fix the issue below and re-run `tauri android init`!
Have you installed the NDK? The `NDK_HOME` environment variable isn't set, and is
required: environment variable not found
Stack trace
No response
Additional context
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 16 (2 by maintainers)
@Rcmane method worked for me as well. I replaced the
$(ls -1 $ANDROID_HOME/ndk)with the literal folder name, in my case29.0.13113456. I think the error is that the$(ls -1 $ANDROID_HOME/ndk)resolves to /Users/ph1/Library/Android/sdk/ndk/\033[34m29.0.13113456\033[39;49m\033[0m, which includes the\033[34mand\033[39;49m\033[0mstrings, which set the text color in the terminal.This is due to my alias of
lstols --color=auto.I could fix the code by: A: setting the ndk folder name manually to 29.0.13113456 NDK_HOME=“$ANDROID_HOME/ndk/<current-version>”
B: making sure that ls does not use colors by adding
--color=never: NDK_HOME=“$ANDROID_HOME/ndk/$(ls --color=never -1 $ANDROID_HOME/ndk)”I made it work by adding environment variables:
export ANDROID_HOME="$HOME/Android/Sdk"export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/28.0.12916984"export NDK_HOME="$ANDROID_HOME/ndk/28.0.12916984"It seems that the method given by tauri prerequisites:
export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"not works, especially when you have more than one ndk verisons.export NDK_HOME=“$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)”
I found a workaround! I named the environment variable “NDKROOT” instead of “NDK_HOME”. Ran
npm run tauri android initandnpm run tauri android buildand it built successfully. Was able to run my app on my phone via wireless debugging too! Can someone confirm?export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"but it looks like latest example same
It is, if you want them to be permanent you have to add that to .zshrc or .zprofile. idk why the docs are missing that
So i assume by “following the prereqs” included this android part right? https://tauri.app/start/prerequisites/#android If so, can you share the output of
ls $ANDROID_HOME/ndk?