Requirements check failed for JDK 1.8 while generating for android

I’m starting with Ionic 4.

I have created my application and its running in web browser. Now, I want to generate apk file for Android.
For that, I run following command

ionic cordova build --release android --verbose

But this gives error as

Preparing Firebase on Android
No scripts found for hook "before_compile".
Running command: /usr/libexec/java_home
Command finished with error code 0: /usr/libexec/java_home
ANDROID_HOME=/Users/anuj/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
Requirements check failed for JDK 1.8
CordovaError: Requirements check failed for JDK 1.8
    at /Users/anuj/code/ionic/no11/platforms/android/cordova/lib/check_reqs.js:362:19
    at _fulfilled (/Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:834:54)
    at /Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:863:30
    at Promise.promise.promiseDispatch (/Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:796:13)
    at /Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:604:44
    at runSingle (/Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:137:13)
    at flush (/Users/anuj/code/ionic/no11/platforms/android/cordova/node_modules/q/q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11)
[ERROR] An error occurred while running subprocess cordova.

I installed java and jdk

java --version
$ java 11.0.2 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

$ javac --version
javac 11.0.2

$ whereis java
/usr/bin/java

$ whereis javac
/usr/bin/javac

Java 11 is not JDK 1.8 (now called JDK 8 I think). You need this specific version for Android tooling.

1 Like