Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error check ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables

To generate apk run

 ionic cordova build android

after some process it generate error.

I set user variables

ANDROID_HOME = C:\Users\Zohab Ud Din\AppData\Local\Android\Sdk\build-tools\29.0.1

JAVA_HOME = C:\Program Files\Java\jdk-12.0.2

PATH = ...;C:\Users\Zohab Ud Din\AppData\Local\Android\Sdk\platform-tools

and I didn't add anything in the system variable

my error is

Checking Java JDK and Android SDK versions
Requirements check failed for JDK 8 ('1.8.*')! Detected version: 12.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\Zohab Ud Din\AppData\Local\Android\Sdk (DEPRECATED)
[ERROR] An error occurred while running subprocess Cordova.



 cordova.cmd build android exited with exit code 1.

Re-running this command with the --verbose flag may provide more information.
like image 725
Ahmad Saeed Avatar asked Jul 22 '19 04:07

Ahmad Saeed


Video Answer


2 Answers

Go to PC properties -> Environment Variable -> Use variable for Your_User_name

Add USED variable FOR Your_User_name-> Add New
Variable: JAVA_HOME
Value: C:\Program Files\Java\jdk1.8.0_221

Variable: ANDROID_SDK_ROOT
Value: C:\Users\Your_User_name\AppData\Local\Android\Sdk

Add following paths to the environment variable PATH:

C:\Users\Your_User_name\AppData\Local\Android\Sdk
C:\Users\Your_User_name\AppData\Local\Android\Sdk\platforms
C:\Users\Your_User_name\AppData\Local\Android\Sdk\platform-tools
C:\Program Files\Java\jdk1.8.0_221
C:\Gradle\gradle-6.3\bin
like image 187
Swati Avatar answered Sep 24 '22 21:09

Swati


I had the same issues, this is the resolution for me.

Please, my configuration is on ionic1 and OSX, so maybe you need to adapt (windows or ubuntu ..)

indication to write in you terminal

Result of your terminal

Requirements check failed for JDK 8 ('1.8.*')! Detected version: 12.0.2

First check your version of JAVA

java -version

If you had something like this, it's not good

java version "14" 2020-03-17
Java(TM) SE Runtime Environment (build 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

Second List your's versions of Java

/usr/libexec/java_home -V

Maybe you have something like this (if you haven't the second Virtual Machine please install it : https://www.java.com/en/download/)

Matching Java Virtual Machines (2):
    14, x86_64: "Java SE 14"    /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
    1.8.0_144, x86_64:  "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Third switch the version of Java

Try this solution first by replace "1.8.0_144" by your version

/usr/libexec/java_home -v 1.8.0_144

If is not working like me, use the second solution to modify bash_profile file (environment variables)

open .bash_profile

Add this line (adapt with your java version)

# SWITCH TO JAVA VERSION 8
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

source ~/.bash_profile

now you should no longer have this error and you can build

After this modification, if you have this message wit build android,

Subproject Path: app
/Users/quentin/Documents/VOLPY/APPS/app-mobile/platforms/android/gradlew: Command failed with exit code EACCES

please try this (you need to be in the project folder)

sudo chmod 755 platforms/android/gradlew

ANDROID_SDK_ROOT=undefined (recommended setting) ANDROID_HOME=C:\Users\Zohab Ud Din\AppData\Local\Android\Sdk (DEPRECATED)

You need to add this variable environment missing : ANDROID_SDK_ROOT (please adapt if you not use osx, looking for "environment variable")

open .bash_profile

copy past lines of ANDROID_HOME by replace by ANDROID_SDK_ROOT and commented by # ANDROID_HOME lines

# Set Android_HOME
export ANDROID_SDK_ROOT=~/Library/Android/sdk/
#export ANDROID_HOME=~/Library/Android/sdk/
  
# Add the Android SDK to the ANDROID_HOME variable
#export PATH=$ANDROID_HOME/platform-tools:$PATH
#export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_SDK_ROOT/platform-tools:$PATH
export PATH=$ANDROID_SDK_ROOT/tools:$PATH

source ~/.bash_profile set ANDROID_SDK_ROOT=~/Library/Android/sdk/

  • Reboot your computer

now you should have this message like this if you build

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/quentin/Library/Android/sdk/ (recommended setting)
ANDROID_HOME=/Users/quentin/Library/Android/sdk/ (DEPRECATED)
...
BUILD SUCCESSFUL

Now everything is ok for you, i hope :)

like image 44
Quentin Avatar answered Sep 21 '22 21:09

Quentin