3

I am a starter to Ionic. When i build myfirst ionic app, i meet error.

 Error:Failed to run "java -version", make sure that you have a JDK installed.

 Error:D:\andorid\ionic\test\platforms\android\cordova\build.bat: command failed with exit code 2

      at ChildProcess.whenDone <C:\users\L\appdata\roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\suoerspawn.js:131:23>
      at ChildProcess. emit <events.js:110:17>
      at maybeClose <child_process.js:1008:16>
      at Process.ChildProcess._handle.onexit <child_process.js:1080:5>

Actulally my java environment was installed correctly. I can run "java -version".

Java version "1.8.0_20"
Java<TM> SE Runtime Environment <build 1.8.0_20-b26>
Java HotSpot<TM> 64-Bit Server VM <build 25.20-b23,mixed mode>

How to solve it?

Linli
  • 31
  • 1
  • 4
  • What is your ant version? ant -version – Aks Mar 08 '15 at 07:30
  • @Aks My ant version is 1.9.4 – Linli Mar 08 '15 at 07:45
  • This http://stackoverflow.com/questions/22868472/failed-to-run-java-even-though-path-is-set-on-windows-8-enterprise-cordova might help – Aks Mar 08 '15 at 07:58
  • 1
    @Aks Thx a lot! I have solved it by myself. I install JDK and JRE in different directory. After I reinstall JDK, ionic build successfully. – Linli Mar 08 '15 at 08:46
  • I used the most simple and crude method to configure Android environment,directly install Android studio to guarantee environment ok. – booyoungxu Dec 27 '16 at 10:43

1 Answers1

5

Try this

Open .bash_profile file with this

nano ~/.bash_profile

After adding

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH
export PATH=/usr/local/bin:$PATH
Community
  • 1
  • 1
veerababu
  • 201
  • 3
  • 6