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

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:

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

# set env vars
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

# download
mkdir /opt/android-ndk-tmp
cd /opt/android-ndk-tmp

# uncompress
unzip -q android-ndk-${ANDROID_NDK_VERSION}

# move to its final location

# remove temp dir
rm -rf /opt/android-ndk-tmp

# add to PATH
# 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! :slight_smile:


ANDROID_NDK_HOME is already added to PATH in Dockerfile:

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

You’re right in case of the environment, but this #how-to was created as a generic guide, which can work even locally on your own Mac/PC :wink:

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

+ unzip -q
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:             |
| Source:                           |

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

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

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}
However, the proper fix seems to be unzipping only once.

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

I ended up using echo "A" | unzip -q 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.

1 Like

I also made a step that can handle both Linux and Mac:

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:

    - git::
        - 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).

1 Like

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


Failed to ensure android components, error: output: > 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.


1 Like