# How to install a specific Android NDK version on the Android/Linux stack

**URL:** <https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400>\
**Category:** Android\
**Tags:** android, android-ndk\
**Created:** [March 7, 2018, 1:17pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400 "2018-03-07T13:17:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [March 7, 2018, 1:17pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/1 "2018-03-07T13:17:11Z")

</div>

If the NDK version which is preinstalled on the Android stack is not the one you want to use, you can install any version via a **Script** step.

Simply add a **Script** step as the very first step in the workflow, with the following content:

```auto
#!/usr/bin/env bash
set -ex

# set env vars
export ANDROID_NDK_VERSION='r15b'
export ANDROID_NDK_HOME='/opt/android-ndk'
# expose for subsequent steps
envman add --key ANDROID_NDK_HOME --value "$ANDROID_NDK_HOME"

# ------------------------------------------------------
# --- Android NDK

# clean up if a previous version is already installed
rm -rf "$ANDROID_NDK_HOME"

# download
mkdir /opt/android-ndk-tmp
cd /opt/android-ndk-tmp
wget -q https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip

# uncompress
unzip -q android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip

# move to its final location
mv ./android-ndk-${ANDROID_NDK_VERSION} ${ANDROID_NDK_HOME}

# remove temp dir
cd ${ANDROID_NDK_HOME}
rm -rf /opt/android-ndk-tmp

# add to PATH
export PATH=${PATH}:${ANDROID_NDK_HOME}
# expose for subsequent steps
envman add --key PATH --value "$PATH"

```

Don’t forget to specify the version, at the top of the script (`ANDROID_NDK_VERSION` variable - in this example it’s set to r15b).

That’s all! 🙂

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [May 14, 2018, 7:21pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/2 "2018-05-14T19:21:55Z")

</div>

`ANDROID_NDK_HOME` is already added to `PATH` in Dockerfile: [https://github.com/bitrise-docker/android-ndk/blob/master/Dockerfile#L30](https://github.com/bitrise-docker/android-ndk/blob/master/Dockerfile#L30)

Value of `ANDROID_NDK_HOME` is not changed so there should be no need to append it again to `PATH`.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [May 15, 2018, 4:59pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/3 "2018-05-15T16:59:36Z")

</div>

You’re right in case of the [bitrise.io](http://bitrise.io) environment, but this #how-to was created as a generic guide, which can work even locally on your own Mac/PC 😉

---

<div class="post-metadata">

**Author:** ![rafaaddison](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@rafaaddison](https://discuss.bitrise.io/u/rafaaddison)\
**Post date:** [July 30, 2018, 2:50pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/4 "2018-07-30T14:50:24Z")

</div>

Hi! Thank you for the script! Nevertheless, I was trying to include it in my builds and faced the following problem:

```
+ unzip -q android-ndk-r10e-linux-x86_64.zip
replace android-ndk-r10e/platforms/android-21/arch-arm/usr/include/linux/netfilter/xt_CONNMARK.h? [y]es, [n]o, [A]ll, [N]one, [r]ename: NULL
(EOF or read error, treating as "[N]one" ...)
| |
+---+---------------------------------------------------------------+----------+
| x | BITRISE - install ndk (exit code: 1) | 129 sec |
+---+---------------------------------------------------------------+----------+
| Issue tracker: https://github.com/bitrise-io/steps-script/issues |
| Source: https://github.com/bitrise-io/steps-script |
+---+---------------------------------------------------------------+----------+

```

Any hints on what is failing and how to fix it? Thank you!

---

<div class="post-metadata">

**Author:** ![tamasbazsonyi](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/tamasbazsonyi/32/1654_2.png) [@tamasbazsonyi](https://discuss.bitrise.io/u/tamasbazsonyi)\
**Post date:** [July 31, 2018, 9:54am UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/5 "2018-07-31T09:54:50Z")

</div>

Hi @rafaaddison,  
Could you send us the build’s URL so we can have a look at the logs?

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [July 31, 2018, 1:01pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/6 "2018-07-31T13:01:00Z")

</div>

> [@rafaaddison](#):
>
> replace android-ndk-r10e (…)

It seems that you are either calling that `unzip` twice or there is `android-ndk-r10e` produced in some other way.

If it is intended that you have an existing `android-ndk-r10e` directory and want to unzip NDK there you can just add `o` option to unizip. So it will be `unzip -qo android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip`.  
However, the proper fix seems to be unzipping only once.

---

<div class="post-metadata">

**Author:** ![rafaaddison](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@rafaaddison](https://discuss.bitrise.io/u/rafaaddison)\
**Post date:** [July 31, 2018, 1:21pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/7 "2018-07-31T13:21:03Z")

</div>

Thanks for the reply. Indeed there seems to be already an existing android-ndk-r10e directory.

I ended up using `echo "A" | unzip -q android-ndk-r10e-linux-x86_64.zip` Which takes the A as the response to the prompt question.

As a side note I needed also to use the -darwin version instead of the linux one.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [November 23, 2018, 2:52pm UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/8 "2018-11-23T14:52:14Z")

</div>

I also made a step that can handle both Linux and Mac: [https://github.com/viktorbenei/bitrise-step-install-android-ndk-version](https://github.com/viktorbenei/bitrise-step-install-android-ndk-version)

As it’s not shared in the StepLib (we probably will include this logic in another step and not have a separate one just for the NDK install) you can include it with the `git::` reference style in your `bitrise.yml`:

```auto
    - git::https://github.com/viktorbenei/bitrise-step-install-android-ndk-version.git@master:
        inputs:
        - android_ndk_version: r12b

```

Once added to the `bitrise.yml` you can use the UI to change the version, or just change the version in the YML (in this example above it’ll install `r12b`).

---

<div class="post-metadata">

**Author:** ![Sebastian.Schlicht](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Sebastian.Schlicht](https://discuss.bitrise.io/u/Sebastian.Schlicht)\
**Post date:** [March 11, 2019, 8:29am UTC](https://discuss.bitrise.io/t/how-to-install-a-specific-android-ndk-version-on-the-android-linux-stack/4400/9 "2019-03-11T08:29:23Z")

</div>

Thank you very much.  
Using install-missing-android-tools@2.3.5 and specifying r19b as NDK version, it failed with following error:

```
Ensure required Android SDK components

Retrying...

Failed to ensure android components, error: output: &gt; Configure project :app

NDK is missing a "platforms" directory.

```

But after I added they install ndk step from Viktor, everything works fine.

Thanks for this “custom” step.

Regards
