On macOS, when running the terminal command
cordova build android
I get an error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/arnas/Android/Sdk (recommended setting)
ANDROID_HOME=/Users/arnas/Android/Sdk (DEPRECATED)
Requirements check failed for JDK 1.8.x! Detected version: 15.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
although running java -version returns java version "1.8.0_291"
My bash_profile settings are:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export ANDROID_HOME=$HOME/Android/Sdk
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
What could be wrong here?
Use the command which java in order to understand the path of your java version 1.8 and then set JAVA_HOME with that path removing the bin/java.
That is:
which java
/usr/bin/java1.8/bin/java
and then replace in your bash_profile your current 'export JAVA_HOME...' with
export JAVA_HOME=/usr/bin/java1.8
What worked for me, was actually setting JAVA_HOME manually in the bash_profile by running nano ~/.bash_profile and entering the line:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home"
I obtained the file path by finding the latest JDK version in the JavaVirtualMachines directory.
Related
We have brand new MacBooks with High Sierra (10.13.6).
Other system info:
JAVA Version: java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
When tried to open Android UIAutomatorViwer we're getting following error:
/Library/Android/sdk/tools/bin/uiautomatorviewer ; exit;
/Library/Android/sdk/tools/lib is not supported. Use -classpath
instead. Error: Could not create the Java Virtual Machine. Error: A
fatal exception has occurred. Program will exit. logout Saving
session... ...copying shared history... ...saving history...truncating
history files... ...completed. Deleting expired sessions...111
completed.
More details:
Java is at: /usr/bin/java
Installed older java(8) JDK
Updated Java version to 1.8 in JAVA_HOME
Commands used to update Java Version:
cd ~/
vim ~/.bash_profile
Updated the JAVA_HOME
Save in vim using :wq!
source ~/.bash_profile
Restart & UiAutomatorViewer is working!
You need Java 8 for uiautomator as mentioned in this as well as other threads. But you can do this without updating the JAVA_HOME variable.
Update the java_exe path in the uiautomator.bat file using any editor.
For Windows systems, find the line
set java_exe=call ..\lib\find_java.bat
Update that to:
set java_exe=C:\Program Files\Java\jdk1.8.0_271\bin\java.exe
In this way, you don't need to update the JAVA_HOME variable which has a higher jdk version(useful for other programs).
If you really don't want to upgrade to Java 11.0 but still want to run then this may help.
uiautomatorviewer works fine with Java version 8. You need not downgrade java version to 1.8. Instead add this method to .bash_profile
uiautomator() {
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$ANDROID_HOME/tools
/Users/<username>/Library/Android/sdk/tools/bin/uiautomatorviewer
}
This would set the JAVA_HOME path to 1.8 and includes android platform and build tools to path variable.
Either,
Restart your terminal to get the changes reflected or
Compile your .bash_profile by . .bash_profile in the current terminal to get it reflected.
Start typing uiautomator in your terminal. It should work !
Work perfectly!
step 1: cd ~/
step 2: vim ~/.bash_profile
-Add text "export ANDROID_HOME ..." to end text.
I'm trying to get Java JDK 8 on my mac. I'm currently running the newest, update to date version 10.0.2 on macOS High Sierra 10.13.6.
I tried to nano .bash_profile and export the command
export JAVA_HOME=$(usr/libexec/java_home -v 1.8)
and then source .bash_profile and it says:
-bash: usr/libexec/java_home: No such file or directory
I tried googling and searching here, but nothing helped so far :/
Your path to java_home is relative and hence cannot be found by your bash script. Try using:
/usr/libexec/java_home
Note: the initial / makes it an absolute path.
I am using Jenkins to build an android project on a mac stadium VM.
When I VNC into the VM, I can build the project just fine. Java is installed at /usr/bin/java, and my $PATH includes /usr/bin.
When I run the same commands from the Jenkins job, it fails with
ERROR: JAVA_HOME is set to an invalid directory: /var/lib/jenkins/jdk1.8.0_25
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
/var/lib/jenkins/jdk... does not exist on the VM. I have also tried updating the build job to include export JAVA_HOME=/usr/bin, but then I get a different error:
Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/bin
All of the other steps seem to work so I can tell that the code is being downloaded to the workspace and everything else is installed properly, and as I said I can build android on the VM from the command line directly.
What can I do to get Jenkins to build on the VM?
The best way to set the JAVA_HOME on a mac is to use java_home after downloading and installing the required JDK from oracle:
export JAVA_HOME=`/usr/libexec/java_home`
If you want Jenkins to use an older version of the JDK ensure use the -v flag:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
To preview the location just type the java_home command into a Terminal:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
I am using Cent-OS.
When I execute "java -version", it displays:
java version "1.7.0_45"
When i execute "echo $JAVA_HOME", it displays
/usr/java/jdk1.8.0_51
I set JAVA_HOME in ~/.bashrc and sourced it.
I also tried setting in /etc/profile and sourced it as well. In profiles, I am setting java home as:
JAVA_HOME=/usr/java/jdk1.8.0_51
export PATH=$PATH:$JAVA_HOME/bin
Please tell me how to set java version to 1.8 only.
I believe 1.7.0_45 is set in your path already, and in order to use 1.8.0_51, export the path as follows,
export PATH=$JAVA_HOME/bin:$PATH
This will add new JAVA path in front of the existing java path. The issue in your export is the new java path is added after the existing path. Hope this helps.
When I installed Java JDK 1.8.x it initially was working, when I rebooted the next day after shutting down over night I get this when I build:
$ ionic build android
Updated the hooks directory to have execute permissions
Running command: d:\installs\nodejs\node.exe d:\htdocs\publicworks\mobile\hooks\after_prepare\010_add_platform_class.js d:/htdocs/publicworks/mobile
add to body class: platform-android
Running command: d:\htdocs\publicworks\mobile\platforms\android\cordova\build.bat
ANDROID_HOME=c:\Users\mtpultz\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45\bin
Running: d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_45\bin
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
d:\htdocs\publicworks\mobile\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true"
But Java is most definitely installed in this directory and nowhere else??? In my terminal:
java -version
Produces the proper output for my JDK:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The environment variables are set to:
JAVA_HOME =
C:\Program Files\Java\jdk1.8.0_45\bin
and the path contains:
D:\installs\nodejs;
C:\Users\mtpultz\AppData\Roaming\npm;
D:\installs\apache-ant\bin;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\tools;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\platform-tools;
Any suggestions?
JAVA_HOME should be set to the home directory of java and not to bin. So replace this:
C:\Program Files\Java\jdk1.8.0_45\bin
with
C:\Program Files\Java\jdk1.8.0_45
java/bin dir is added to PATH system variable to run java from anywhere.
Do one thing. This will Help You
Remove "\bin" from your JAVA_HOME path. Mean give path only till.
C:\Program Files\Java\jdk1.8.0_45
It will work with you.
For Linux user:
$sudo gedit $HOME/.bashrc
write at end
#Android Path
export ANDROID_HOME=${HOME}/Android/Sdk
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools
export PATH
#JAVA
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
export JAVA_HOME
$source ~/.bashrc
after that open
$sudo gedit /etc/environment
and add at end
JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
$source /etc/environment
after wasting 3 days finally i got some solutions. these are definitely works when you found these errors.
1.Error: JAVA_HOME is set to an invalid directory
JAVA_HOME should be set to the home directory of java and not to bin. So replace this:
C:\Program Files\Java\jdk1.8.0_45\bin
with
C:\Program Files\Java\jdk1.8.0_45
java/bin dir is added to PATH system variable to run java from anywhere
Failed to install 'cordova-plugin-whitelist': Error using forcedroid command line
check your environments variables
1. android platforms tools
2. android tools
3. sdk location
4. git location
cordova - Error: Failed to fetch platform android
the only solution is
cordova platform add android --nofetch
Make sure you use the Java SE SDK and not the Java EE SDK, that solved the problem for me.
Make sure that your JAVA_HOME is having the following path and install JDK SE.
C:\Program Files\Java\jdk1.8.0_131