1
votes

I have a problem with the command ionic cordova build android.When I try to launch this command I have this error > cordova build android Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=undefined (recommended setting) ANDROID_HOME=/usr/lib/android-sdk (DEPRECATED) Requirements check failed for JDK 8 ('1.8.*')! Detected version: 11.0.3 Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables. [ERROR] An error occurred while running subprocess cordova.

5
you will have to set environment variables for android home, try re-installing android studio.Nidhin Joseph

5 Answers

1
votes

It is clearly saying you didn't set the java and environment paths. To set up the environment follow Android environment setup Link

0
votes

You need to set environment paths.

If your OS is ubuntu, try below.

sudo gedit ~/.bashrc

in gedit editor, add these lines

export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Don't forget to save.

0
votes

I used to have the same issue in WebStorm and found solution. The issue is due to WebStorm was written in Java and use v11.0.3 inside. So, do the following: 1. Open Webstorm --> Help --> Find action --> Switch boot JDK --> Change path to your v.1.8. In my case it's: "C:\Program Files\Java\jdk1.8.0_231" 2. add "JDK_HOME" in environment variables in your OS and set it's value: "C:\Program Files\Java\jdk1.8.0_231" Restart your Webstorm. That's it!

This also might be helpful: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

0
votes

As others have said you need to update path variables, I want to add a few more parameters along these.

In the project, directory use this command to check Cordova compatibility. $ ionic cordova requirements This should show what you are missing. Cordova needs Java JDK, Android SDK, Android target, Gradle.

  1. First install Java JDK as instructed here.
  2. Then you need to install Android SDK. If not installed, you can install it from here.
  3. You need to install Android Target, for this open SDK Manager in android studio and install android targets. Install a latest one as well as an old one.
  4. Install gradle. Use this link to install gradle.

Finally you need to sum up all these in path so command-line can recognise these. Open .bashrc with $ ~/.bashrc and add these lines. (If you haven't done already).

export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" # change location
export PATH=$JAVA_HOME/bin:$PATH


export GRADLE_HOME=/opt/gradle/gradle-5.2.1 # change location
export PATH=${GRADLE_HOME}/bin:${PATH}


export ANDROID_HOME=$HOME/Android/Sdk # change location
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

Change locations based on your installation directory.

NB: Make sure to add this line export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin as old version of android studio's command-line has been deprecated and this is the updated command-line tool.

After this, reload the bash with $ sudo source ~/.bashrc

Then again check the requirements with ionic cordova requirements and this should display:

> cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-26,android-23
Gradle: installed /opt/gradle/gradle-5.2.1/bin/gradle
0
votes

I was stuck on this for a bit, I had JDK 8 (1.8) installed but it wasn't finding it - adding the second line

export PATH=$JAVA_HOME/bin:$PATH

in my .bash_profile then running source ~/.bash_profile Saved the day - here's by full .bash_profile for reference

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home"
export PATH=$JAVA_HOME/bin:$PATH
export ANDROID_HOME=/Users/dylan/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/dylan/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/dylan/.android/avd
export PATH="${PATH}:/$ANDROID_HOME/platform-tools:/$ANDROID_HOME/tools:/$ANDROID_HOME/tools/bin"
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd