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

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 38 (9 by maintainers)

Most upvoted comments

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.

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

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

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.

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

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?

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.

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

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…”

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.