Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova is running the wrong Java version. How do I get Cordova to run a specific Java version?

[javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release

and

error: strings in switch are not supported in -source 1.5
    [javac]    switch (xmlData[i][1]) {
    [javac]           ^
    [javac]   (use -source 7 or higher to enable strings in switch)

I am getting warnings and errors that I am running Java 1.5 when compiling an APK with Cordova for Android. I can't use strings in switch statements. (the compilation process errors)

My system is 64-bit Windows 7. My Cordova version is 3.5. I am using git-scm. (http://git-scm.com/)

  • I am running this command: cordova run android --release.
  • My Java environment variable lists C:\Program Files\Java\jdk1.8.0_20 as the Java directory.
  • My path enviroment variable sets the Java path as the first item in the list.
  • Every Java patch and version is uninstalled except what I just re-installed from Oracle's site.
  • I restarted my computer.
  • java -version gives me java version "1.8.0_20".
  • javac -version gives me javac 1.8.0_20.
  • All my targets are =android-19, =debug, or =release.
  • android:minSdkVersion is always set to "14", everywhere.
  • android:targetSdkVersion is always set to "19", everywhere.

How can I force Cordova to run Java 8?

like image 526
Agamemnus Avatar asked Mar 18 '23 05:03

Agamemnus


2 Answers

To fix for command line builds, add these lines (or set appropriate values if already present) to your ant build.xml property file (for example if using Android SDK, it's in ${sdk.dir}/tools/ant/build.xml):

<property name="java.target" value="1.7" />
<property name="java.source" value="1.7" />
like image 153
cdelacroix Avatar answered Mar 20 '23 18:03

cdelacroix


  1. Right-click on your project(Package Explorer) and select "Android Tools -> Fix Project Properties"
  2. Right-click on your project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.7 or 1.8 from "Compiler compliance settings" select box.
  3. then Rebuild your project (Project -> Clean)
like image 44
AAhad Avatar answered Mar 20 '23 17:03

AAhad