diff --git a/app/src/main/jniLibs/build.sh b/app/src/main/jniLibs/build.sh
index 0b6995369451c24ec169d2e0c6a21067902ed9e8..fbd56d629332c2272334974e601a4ea7a0bc9b2f 100755
--- a/app/src/main/jniLibs/build.sh
+++ b/app/src/main/jniLibs/build.sh
@@ -69,6 +69,17 @@ if [ ! -d "$GMP" ]; then
     exit 1
 fi
 
+if [ `uname -s` = "Darwin" ]; then
+    export JAVA_HOME=$(/usr/libexec/java_home)
+else
+    [ -z $JAVA_HOME ] && . $I2PBASE/core/c/find-java-home
+fi
+if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
+    echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'"
+    echo "Please set JAVA_HOME to a java home that has the JNI"
+    exit 1
+fi
+
 #
 # API level, pulled from ../AndroidManifest.xml
 #
@@ -153,17 +164,6 @@ fi
 echo "Building GMP..."
 make || exit 1
 
-if [ `uname -s` = "Darwin" ]; then
-    export JAVA_HOME=$(/usr/libexec/java_home)
-else
-    [ -z $JAVA_HOME ] && . $I2PBASE/core/c/find-java-home
-fi
-if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
-    echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'"
-    echo "Please set JAVA_HOME to a java home that has the JNI"
-    exit 1
-fi
-
 COMPILEFLAGS="-fPIC -Wall"
 INCLUDES="-I. -I$JBIGI/jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
 LINKFLAGS="-shared -Wl,-soname,libjbigi.so,--fix-cortex-a8"