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)

Most upvoted comments

@Rcmane method worked for me as well. I replaced the $(ls -1 $ANDROID_HOME/ndk) with the literal folder name, in my case 29.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[34m and \033[39;49m\033[0m strings, which set the text color in the terminal.

This is due to my alias of ls to ls --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 init and npm run tauri android build and 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)"

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble
ls -1 $ANDROID_HOME/ndk
25.0.8775105
26.1.10909125
"dependencies": {
    "@tauri-apps/api": "^2.0.0-alpha.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@tauri-apps/cli": "^2.0.0-alpha.10",
    "@types/react": "^18.2.15",
    "@types/react-dom": "^18.2.7",
    "@vitejs/plugin-react": "^4.0.3",
    "internal-ip": "^8.0.0",
    "typescript": "^5.0.2",
    "vite": "^4.4.4"
  },
yarn tauri android init
yarn run v1.22.22
$ 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 is set, but doesn't point to an
    existing directory.
victory: Project generated successfully!
    Make cool apps! 🌻 🐕 🎉
Done in 1.11s.

but it looks like latest example same

pnpm create tauri-app
cd tauri-app
pnpm install
pnpm tauri dev
 pnpm tauri android dev

> tauri-app@0.1.0 tauri /home/burak/Desktop/tauri/tauri-app
> tauri "android" "dev"

Have you installed the NDK? The `NDK_HOME` environment variable is set, but doesn't point to an exis
ting directory.
    Error Have you installed the NDK? The `NDK_HOME` environment variable is set, but doesn't point
to an existing directory.
 ELIFECYCLE  Command failed with exit code 1.
 ```

I’m not sure if this is expected behavior, but entering these commands into my terminal doesn’t seem to stick when I set these variables in the project folder via the terminal in my IDE (vsCode).

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 ?