Nativescript-cli: [OpenJDK] tns platform add android: Error executing command 'javac'.

Created on 27 Nov 2016  ·  38Comments  ·  Source: NativeScript/nativescript-cli

Following the tutorial, step 1-3:

~/hack/nativescript/sample-Groceries$ tns platform add android
Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.
~/hack/nativescript/sample-Groceries$ echo $JAVA_HOME
/usr/lib64/jvm/java
~/hack/nativescript/sample-Groceries$ javac
Usage: javac <options> <source files>
where possible options include:
  @<filename>                  Read options and filenames from file
  -Akey[=value]                Options to pass to annotation processors
  --add-modules <module>(,<module>)*
        Root modules to resolve in addition to the initial modules, or all modules
        on the module path if <module> is ALL-MODULE-PATH.
  --boot-class-path <path>, -bootclasspath <path>
        Override location of bootstrap class files
  --class-path <path>, -classpath <path>, -cp <path>
        Specify where to find user class files and annotation processors
  -d <directory>               Specify where to place generated class files
  -deprecation
        Output source locations where deprecated APIs are used
  -encoding <encoding>         Specify character encoding used by source files
  -endorseddirs <dirs>         Override location of endorsed standards path
  -extdirs <dirs>              Override location of installed extensions
  -g                           Generate all debugging info
  -g:{[lines, vars, source],[lines, vars, source],[lines, vars, source]}
        Generate only some debugging info
  -g:none                      Generate no debugging info
  -h <directory>
        Specify where to place generated native header files
  --help, -help                Print a synopsis of standard options
  -implicit:{[none, class],[none, class]}
        Specify whether or not to generate class files for implicitly referenced files
  -J<flag>                     Pass <flag> directly to the runtime system
  --limit-modules <module>(,<module>)*
        Limit the universe of observable modules
  --module <module-name>, -m <module-name>
        Compile only the specified module, check timestamps
  --module-path <path>, -p <path>
        Specify where to find application modules
  --module-source-path <module-source-path>
        Specify where to find input source files for multiple modules
  -nowarn                      Generate no warnings
  -parameters
        Generate metadata for reflection on method parameters
  -proc:{[none, only],[none, only]}
        Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...]
        Names of the annotation processors to run; bypasses default discovery process
  --processor-module-path <path>
        Specify a module path where to find annotation processors
  --processor-path <path>, -processorpath <path>
        Specify where to find annotation processors
  -profile <profile>
        Check that API used is available in the specified profile
  --release <release>
        Compile for a specific VM version. Supported targets: 6, 7, 8, 9
  -s <directory>               Specify where to place generated source files
  -source <release>
        Provide source compatibility with specified release
  --source-path <path>, -sourcepath <path>
        Specify where to find input source files
  --system <jdk>|none          Override location of system modules
  -target <release>            Generate class files for specific VM version
  --upgrade-module-path <path>
        Override location of upgradeable modules
  -verbose                     Output messages about what the compiler is doing
  -version                     Version information
  -Werror                      Terminate compilation if warnings occur
  -X                           Print a synopsis of nonstandard options

The message from the tns platform command is useless because it does not say what the error is.

Most helpful comment

A couple of tips for people running into this (at least for MAC some of these worked).
Make sure your using JDK 8, - 9 doesn't work (the docs have been updated recently to reflect that).

Next, if you're getting the JAVA_HOME issues (even though you exported them at some other time), update your bash_profile

nano .bash_profile

// in the file add
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/usr/local/share/android-sdk

// then save and exit
ctrl+o  (then Y for yes)
ctrl+x

Hope that helps others, got me able to get through tns doctor.

All 38 comments

Have you exported the $JAVA_HOME? It must be visible to the child process.

The variable is already set at an earlier time. Of course it will be part of the environment of child processes spawned from the shell:

$ echo $JAVA_HOME
/usr/lib64/jvm/java
$ perl -E'say $ENV{JAVA_HOME}'
/usr/lib64/jvm/java
$ node -p process.env.JAVA_HOME
/usr/lib64/jvm/java

Why is this tagged as question? I am not asking a question, I am reporting a bug. Why do you close the ticket before it's resolved? Kindly reopen.

@PanayotCankov

Having the same issue here. Everything is configured as it should be, but I keep getting the error, no matter which tns command I try.

@daxim My problem when away after setting the OpenJDK v8.

sudo update-alternatives --config java
sudo update-alternatives --config javac

I have the same problem. Any solution?

Hey guys, sorry for the late reaction. Do you still have this issue? @alextfos @kristoftorfs @daxim

@cdarken ☝️

is this safe to ignore? since android studio works fine for me despite this warning. message _what_ that error was when executing javac would be nice

Hi @aep

Can you elaborate a bit more on is this safe to ignore?
Do you see some errors now, what are the steps to reproduce them?

Closing due to inactivity.

yep, still getting the message, but everything works fine.

$ javac -version 
javac 1.8.0_141

Hi @aep

Is your java OpenJDK or it is Oracle's JDK?

Did you try this solution?

@dtopuzov openjdk.
i dont use ubuntu. so no.
also i cant really reproduce this anymore, after a system update, sorry.
maybe it's already fixed in the meantime?

Thanks, for the info, it looks like we have this issue only with OpenJDK (we recommend Oracle's JDK).

I'm having the same problem. I'm using Oracle's JDK, JAVA_HOME is in the PATH, android studios works OK and also the emulator.

But tns run android do not work, it say:

"Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable."

Please, fix this

I have the same problem I use javac in my terminal fine but the script say "Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable." when "Verifying CocoaPods. This may take some time, please be patient.."

+1

same issue here on a mac

ok I've been dealing with this since yesterday and the issue finally went away.

I had jdk-9 and jdk-8 so I removed both using the commands in this stackoverflow thread
https://stackoverflow.com/questions/19039752/removing-java-8-jdk-from-mac

Then reinstalled jdk-8u144-macosx-x64.dmg after restarting.
Once that was done, I ran tns doctor but it complained about android sdks so I added the ANDROID_HOME variable path again.
After that, I ran tns doctor one more time and the javac error went away.

Hopefully this helps someone.

@mnovak20 is there a reason why you chose that version of the JDK and not JDK 9?

So, still not working.
Nativscript version: 3.2.1
Javac version: 9
Java version: 9
ANDROID_HOME: /Users/username/Library/Android/sdk
JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home

When I run tns run android --emulator I get

Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.

I tried @mnovak20 solution and no luck.

I originally started with 9, that didn't work so I installed 8, that still didn't work.
At that point I had 2 JDKs so I uninstalled both and installed 8 again.
That's when tns doctor stopped throwing errors.

It may work fine with JDK9 but it just didn't for me.

Same goes for me, I was using java-9-openjdk and it was showing the same error, I then installed java-8-oracle (according to the documentation) and that fixed it.

@Spatlani and @mnovak20 that did it. I used jdk-8u144 and reset the JAVA_HOME variable. Thanks all!

Hi
Same here, it does not seem to work with the latest version of the JDK (jdk-9.0.1)

A couple of tips for people running into this (at least for MAC some of these worked).
Make sure your using JDK 8, - 9 doesn't work (the docs have been updated recently to reflect that).

Next, if you're getting the JAVA_HOME issues (even though you exported them at some other time), update your bash_profile

nano .bash_profile

// in the file add
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/usr/local/share/android-sdk

// then save and exit
ctrl+o  (then Y for yes)
ctrl+x

Hope that helps others, got me able to get through tns doctor.

You shouldn't need to remove and reinstall JDK versions.

Run javac -version to see which version is being exported. For instance, this will return:

$ javac -version
javac 9.0.1

Use this command to check currently installed versions:
$ /usr/libexec/java_home -V

It will show you something like:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    9.0.1, x86_64:  "Java SE 9.0.1" /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
    1.8.0_131, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

If you have multiple versions you can select the desired $JAVA_HOME export like so:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

(if you have multiple versions of 1.8 for instance you should specify the entire version number: 1.8.0_131. If it's unique, 1.8 will do.)

Add that export to ~/.bash_profile to make it default and restart the terminal.

Output of javac -version is now:

$ javac -version
javac 1.8.0_131

Running tns doctor should not show javac error anymore. Hope it helps.

delete all java version and install java 8. I solved.

i sloved this problem by fixing my .bash_rc JAVA_HOME
i used this line
export JAVA_HOME=ls -d /usr/lib/jvm/java--openjdk-/ | head -n 1

I fixed the same issue with:
export JAVA_HOME=$(/usr/libexec/java_home)

Hey guys,
We have added a check for Java 9 and latest CLI reports it is not supported. I see some of you had issues with setting JAVA_HOME, but after fixing the variable, everything works fine. Can we consider the issue as resolved or you have some suggestions how to improve the checks of tns doctor?

I would agree that this should be closed. I resolved this by setting my JAVA_HOME to version 1.8. After reinstalling it of course. :)

you have some suggestions how to improve the checks of tns doctor?

@rosen-vladimirov, start by not throwing away the error message. It's more than a year later, Java 8, 9, 10 and 11 came out and passed you by.

Ubuntu 16.04 Fix

Modification to @MarkPieszak 's comment: https://github.com/NativeScript/nativescript-cli/issues/2265#issuecomment-340232515

vim ~/.profile

Then, at the bottom of the file use i to insert the following:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export JAVA_HOME=$(/usr/lib/jvm/{your_java_version}/bin)
export PATH=$PATH:$JAVA_HOME

Then, save (ctrl+x) and either run the following command:

source ~/.profile

OR restart your terminal.

Hope this helps!

Hey all,

Regarding the support for Java 10, we've created a new issue, you can follow it here: https://github.com/NativeScript/nativescript-cli/issues/3605 (Note - it is planned for the 4.1.0 release)

I'm closing this thread as the initial issue has been resolved.

Yeap, just run this http://i.imgur.com/ytUsVX5.png from https://docs.nativescript.org/angular/start/ns-setup-linux for linux, for windows and macOS please take a look on docs.

Solved this under ubuntu 18.

I had multiple JDK installation

the problem is setting JAVA_HOME with generated dynamic values, for instance:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
export JAVA_HOME=$(/usr/libexec/java_home)

worked in terminal, but produce the error in tns

when I used a static complete path, it worked:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64

probably these dynamics values change their values under tns and use another version of the JVM

Was this page helpful?
0 / 5 - 0 ratings