NPE when setting ANDROID_NDK_ROOT to an non-existing path

I’m using a generic Android project created by Android Studio

ANDROID_NDK_ROOT is set but to a non-existing path.

$ ./gradlew --version
Gradle 2.12

Build time:   2016-03-14 08:32:03 UTC
Build number: none
Revision:     b29fbb64ad6b068cb3f05f7e40dc670472129bc0

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_74 (Oracle Corporation 25.74-b02)
OS:           Linux 4.4.1-2-ARCH amd64

Running ./gradlew :app:assembleRelease crashes gradle with a NullPointerException.

Full stacktrace is here: