How to install Android NDK on Ubuntu Linux ?
The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.
To install and configure the NDK, follow these steps:
Download android ndk Linux 64 bit from http://developer.android.com/ndk/downloads/index.html , when we written this post, the latest Android version is R23B, which we downloaded and copied to /home/myuser/Android directory. Now, Lets extract this zip as,
$ unzip android-ndk-r23b-linux.zip
This will extract as “Extracting android-ndk-r23b” into folder “android-ndk-r23b” in ~/Android directory. When uncompressed, the NDK files are contained in a directory called android-ndk- . You can rename the NDK directory if necessary and you can move it to any location on your computer.
Export the NDK path into environment variables,
$ export PATH=$PATH:/home/myuser/Android/android-ndk-r23b
OR You can also edit your ~/.bashrc file and append above line to add NDK permanently to your path to avoid typing above command always.
Check if ndk-build is added to environment,
$ which ndk-build /home/myuser/Android/android-ndk-r23b/ndk-build
Sometimes, you may need to set NDK_HOME evnvironment variable which you can do the same way as above,
$ export NDK_HOME=/home/myuser/Android/android-ndk-r23b
How to install android ndk in linux?
I have downloaded android NDK from here: http://developer.android.com/tools/sdk/ndk/index.html
for Linux 64-bit (x86) android-ndk-r10c-linux-x86_64.bin. How I do install it? The instructions don’t work. My OS is
57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
10 Answers 10
The Standard Way
Android’s NDK now ships as an self extracting executable. You likely need to set the executable bit:
$ chmod +x android-ndk-r10c-linux-x86_64.bin $ ./android-ndk-r10c-linux-x86_64.bin
The above will cause the NDK to extract into the current working directory.
Manual Extraction
Since the .bin file is really just a 7-Zip self extracting archive, you can manually extract the contents if needed:
$ 7za x -o/path/to/extract/to/ android-ndk-r10c-linux-x86_64.bin
7-Zip is available in Ubuntu for example via apt-get:
$ sudo apt-get install p7zip-full
Update
As of at least r14b on the NDK download page, we’re back to standard ZIP archives.
You may want to post some more information other than «It doesn’t work». See stackoverflow.com/help/how-to-ask
./android-ndk-r10c-linux-x86_64.bin: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
@Vardan95: That is answered here: stackoverflow.com/questions/11471722/… Alternatively, you can use the manual instructions I added.
and where can this .bin file be found? All I see are .zip files, (and no README to be seen anywhere, shame on you Google)
If you already have AndroidStudio installed:
You can install NDK using the SDK Manager from within Android Studio
From an open project, select Tools > Android > SDK Manager from the menu bar. Click the SDK Tools tab. Check the boxes next to LLDB, CMake, and NDK. Apply
ubuntu does not install by default Android Studio and nowhere in the question is mentioned that it is installed. So the answer is incorrect unless: First install Android Studio is provided before «install NDK using the SDK Manager from within Android Studio«
Another way to download and install (unpack) it (size of zip is ~820MB, unzipped is ~2.9G):
wget https://dl.google.com/android/repository/android-ndk-r20-linux-x86_64.zip unzip android-ndk-r20-linux-x86_64.zip
Go to the directory where you downloaded it. Then execute:
chmod +x android-ndk-r10c-linux-x86_64.bin ./android-ndk-r10c-linux-x86_64.bin
It should unpack right there. The toolchain will be in android-ndk-r10c-linux-x86_64/toolchains. The root folder might have a slightly different name.
Unfortunately this is not correct, because android-ndk-r10c-linux-x86_64.bin is an ELF executable, not a shell script.
Install 7-Zip via apt-get like this
$ sudo apt-get install p7zip-full
go to folder where your ndk bin is and then execute the command
I have androidBBQ which is archlinux based, installed using vmware. But I guess my instructions should be the same for any linux distribution. I used AndroidStudio’s built-in SDK manager, to try installing NDK. Download failed because there was no space in /tmp. Turns out that most Linux distros have ramdisk baesd tmpfs (temporary file system in RAM which is mounted at /tmp) and there is no separate partition which could be extended. /tmp is mounted usually by using 50% of available RAM.
Install NDK using Android Studio’s built-in SDK manager ->not so convenient
a) Extend /tmp
I edited my fstab as root, using this command :
I appended this line to my fstab
none /tmp tmpfs size=8G 0 0
Note: If no such line exists, add above line at end of fstab. If any such line exists, it means you had already extended your /tmp and it was still insufficient. So, only change the «size» value, by raising it by a few GBs.
Then I rebooted. Once I did, my /tmp was extended to 8GB size. For development purposes, I guess we should readily extend our /tmp because we will have to do it anyway some time later. Size of /tmp is not dependent on free space in our hard disk (whether virtual or physical).
b) run NDK install again
I ran the NDK install from within AndroidStudio again. It had to download the NDK zip afresh. Unfrotunate that there is no resume/recheck function to resurrect broken installs. My download speed was slow, so I minimized the virtual linux’s window and continued to read news. Later, I guess memory/page swapping occurred. The download failed. I restarted Linux and restarted NDK install the same way. This time, I let the virtual Linux machine stay on foreground. NDK installed fine with this log :
Manual NDK install in Linux (preferable) I am amazed that official Android dev section did not bother indicating exact install location of Android NDK. Android Studio looks for NDK at: