28

I had set the ANDROID_NDK_HOME as /Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b using a mac osx application called Environment Variables.

I had confirmed that it set the path correctly in Terminal

echo $ANDROID_NDK_HOME

But when I run a shell file in a Android Studio project which invokes ndk-build I get the following error

ndk-build: command not found

How to make sure that ndk-build is in your build path ?

How to set ndk-build in my build path ?

Thanks for any help

stackoverflowuser2010
  • 38,621
  • 48
  • 169
  • 217
Shajo
  • 873
  • 2
  • 11
  • 22
  • 2
    Two things: Are you sure that this directory is the correct one? `ndk-build` is directly in this directory. Secondly, what shell file are you running exactly? – JBL Apr 23 '15 at 09:14
  • I am trying to run this file https://github.com/schwabe/ics-openvpn/blob/master/main/misc/build-native.sh – Shajo Apr 23 '15 at 14:21

4 Answers4

31

Well, this is actually not enough to make the system aware of the path. You must add this path to the PATH system variable. In your case, all you have to do is to add the following line to your terminal configuration file (which should be under your home directory, named .bashrc if you kept the default terminal, full path: ~/.bashrc):

export PATH=$PATH:/Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b

What this line does is actually adding the path to your Android NDK directory to the PATH variable. You export a variable named PATH with its current content plus the directory of your NDK.

Step by step:

  • Go in the home directory
  • Edit .bashrc
  • Add the line I showed above
  • Save, exit, then restart bash (you just have to type bash, then enter)
JBL
  • 12,588
  • 4
  • 53
  • 84
  • Thanks for answering my question I have some doubts ...Consider I have uninstalled the application Environment Variables...Can you give me the steps from begining...My NDK builder is at /Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b ..Now I have opened the terminal what are the next steps ? – Shajo Apr 25 '15 at 15:04
  • `~/ ` means go in home directory to edit `.bashrc` ..when I try `~/ .bashrc` I get no such file or directory. – Shajo Apr 26 '15 at 10:14
  • Later I found there is not `/bashrc` using this command ls -a which showed there is a `.bash_profile` and `.bash_history` so I thought lets edit it ` sudo ~/.bash_profile` But this is what I got ` command not found` Ref:http://stackoverflow.com/a/19664882/3856173 ..I hope you can help me – Shajo Apr 26 '15 at 10:38
  • 1
    No, you must edit this file, it's not a command that you must execute. For example, you should type `nano .bashrc`. Try to create the file, add this line, and try again. If it doesn't work, add the line mentioned in this [answer](http://superuser.com/a/147699/243369) to get it to work. – JBL Apr 26 '15 at 10:41
  • I will try and let u know...oneupvote for your effort..if works I'll accept your post as answer – Shajo May 14 '15 at 06:55
  • Hi @JBL Where is .bashrc file on MAC OS. I go to Home directory > go to User > Maidul ISlam> There is no .bashrc visible file. How can I find that. Please let me know. – Md Maidul Islam Apr 26 '16 at 06:07
  • @Maid786 The `.bashrc` file should be in your home directory (a.k.a. `~`). If it isn't, you can create it yourself. Please also consider that this may depend on your shell. For example, if you're using `zsh`, the file you want to edit is `~/.zshrc`. – JBL Apr 26 '16 at 08:30
  • 7
    Note that if you installed the NDK from Android Studio's built-in SDK manager/tools, than the path would be `/Users/_username_/Library/Android/sdk/ndk-bundle` – Yoav Feuerstein Dec 28 '16 at 15:15
30

For mac use this: Open your .bash_profile file with a text editor. .bash_profile is by default found in home directory. Eg /Users/john

the assumption is: you have downloaded the android sdk and ndk to /User/john/Android or you can find the path from Android Studio by going to

Project Structure > SDK Location, pay attention to Android SDK location & Android NDK location

export ANDROID_SDK=/Users/john/Android/sdk
export ANDROID_NDK=/Users/john/Android/sdk/ndk-bundle
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"

Then save the above lines to your .bash_profile file. Close it and try typing this on your terminal

ndk-build

if the response is like below, you are good to go

Android NDK: Could not find application project directory !    
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.    
/Users/john/Android/sdk/ndk-bundle/build/core/build-local.mk:143: ***   Android NDK: Aborting    .  Stop.

The assumption here is you have downloaded your android sdk to /Users/john/Android

display name
  • 879
  • 11
  • 20
  • Hi @James Bond Where is .bashrc file on MAC OS. I go to Home directory > go to User > Maidul ISlam> There is no .bashrc visible file. How can I find that. Please let me know. – Md Maidul Islam Apr 26 '16 at 06:09
  • 1
    http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html the above link might be of help – display name Apr 26 '16 at 17:11
  • Man...u r a genius.. It works.. Btw to all stalker out there , if it doesn't work then logout and login after changing bash_profile... and make sure that the ndk directory is within sdk. it tool for me several weeks to realise this truth –  Jun 13 '17 at 17:18
12

In case this helps anyone, I installed the Android NDK using Android Studio on MacOS by following the instructions on the android.com NDK webpage: I selected Tools --> Android --> SDK Manager and then selected NDK. Android Studio then installed the downloaded files under:

/Users/user.name/Library/Android/sdk/

That directory is the same one that is listed on the SDK Manager window inside Android Studio. Underneath that directory is another directory ndk-bundle, which has all the NDK tools.

Thus, I added this to my path:

/Users/user.name/Library/Android/sdk/ndk-bundle/
stackoverflowuser2010
  • 38,621
  • 48
  • 169
  • 217
4
  • cd to path you have to set.

  • Enter in Terminal: echo "export PATH=$PATH:$ANDROID_NDK_HOME" | sudo tee -a /etc/profile

Will
  • 24,082
  • 14
  • 97
  • 108