3
votes

I have created new BlankCordovaApp, and simply can't run it on Andorid, i have no problems with running it on Windows. Moreover, i can build and run it manually via cmd:

 cordova run android

Visual studio output:

1>  ------ Build configuration options: --debug
1>  Executing "before_compile"  hook for all plugins.
1>  ANDROID_HOME=C:\Users\dima-\AppData\Local\Android\sdk
1>  JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_55
1>  Reading build config file: E:\dima-\Documents\Visual Studio 2015\Projects\BlankCordovaApp1\BlankCordovaApp1\build.json
1>MSBUILD : cordova-build warning : Note: Some input files use or override a deprecated API.
1>  Note: Some input files use or override a deprecated API.
1>MSBUILD : cordova-build warning : Note: Recompile with -Xlint:deprecation for details.
1>  Note: Recompile with -Xlint:deprecation for details.
1>MSBUILD : cordova-build error : java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
1>  java.lang.UnsupportedClassVersionError com/android/dx/command/Main : Unsupported major.minor version 52.0
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.defineClass1(Native Method)
1>      at java.lang.ClassLoader.defineClass1(Native Method)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
1>      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
1>  :transformClassesWithDexForDebug FAILED
1>
1>  BUILD FAILED
1>
1>  Total time: 5.112 secs
1>MSBUILD : cordova-build error :  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
1>      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
1>      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
1>      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
1>      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
1>      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
1>MSBUILD : cordova-build error :  at java.security.AccessController.doPrivileged(Native Method)
1>      at java.security.AccessController.doPrivileged(Native Method)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
1>      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
1>      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
1>MSBUILD : cordova-build error :  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
1>      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
1>      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
1>MSBUILD : cordova-build error :  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
1>      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
1>MSBUILD : cordova-build error : Picked up _JAVA_OPTIONS: -Xmx512M
1>  Picked up _JAVA_OPTIONS: -Xmx512M
1>MSBUILD : cordova-build error : Exception in thread "main"
1>  Exception in thread "main"
1>MSBUILD : cordova-build error : java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
1>  java.lang.UnsupportedClassVersionError com/android/dx/command/Main : Unsupported major.minor version 52.0
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.defineClass1(Native Method)
1>      at java.lang.ClassLoader.defineClass1(Native Method)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
1>      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
1>MSBUILD : cordova-build error :  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
1>      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
1>      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
1>      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
1>      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
1>      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
1>MSBUILD : cordova-build error :  at java.security.AccessController.doPrivileged(Native Method)
1>      at java.security.AccessController.doPrivileged(Native Method)
1>MSBUILD : cordova-build error :  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
1>      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
1>      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
1>MSBUILD : cordova-build error :  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
1>      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
1>MSBUILD : cordova-build error :  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
1>      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
1>MSBUILD : cordova-build error :  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
1>      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
1>MSBUILD : cordova-build error : Picked up _JAVA_OPTIONS: -Xmx512M
1>  Picked up _JAVA_OPTIONS: -Xmx512M
1>MSBUILD : cordova-build error : Exception in thread "main"
1>  Exception in thread "main"
1>
1>MSBUILD : cordova-build error : FAILURE: Build failed with an exception.
1>  FAILURE: Build failed with an exception.
1>
1>MSBUILD : cordova-build error : * What went wrong:
1>  * What went wrong:
1>MSBUILD : cordova-build error : Execution failed for task ':transformClassesWithDexForDebug'.
1>  Execution failed for task ':transformClassesWithDexForDebug'.
1>MSBUILD : cordova-build error : > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_55\bin\java.exe'' finished with non-zero exit value 1
1>  > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_55\bin\java.exe'' finished with non-zero exit value 1

CMD output:


    E:\dima-\Documents\Visual Studio 2015\Projects\BlankCordovaApp1\BlankCordovaApp1>cordova run android
    ANDROID_HOME=C:\Users\dima-\AppData\Local\Android\sdk
    JAVA_HOME=C:\Program Files\java\jdk1.8.0_92
    No target specified, deploying to device 'LGH818fdb0daf3'.
    Reading build config file: E:\dima-\Documents\Visual Studio 2015\Projects\BlankCordovaApp1\BlankCordovaApp1\build.json
========================
//////////////////////
========================

    BUILD SUCCESSFUL

    Total time: 5.313 secs
    Built the following apk(s):
            E:/dima-/Documents/Visual Studio 2015/Projects/BlankCordovaApp1/BlankCordovaApp1/platforms/android/build/outputs/apk/android-debug.apk
    Using apk: E:/dima-/Documents/Visual Studio 2015/Projects/BlankCordovaApp1/BlankCordovaApp1/platforms/android/build/outputs/apk/android-debug.apk
    LAUNCH SUCCESS

5
You say you "can build", but your Visual Studio output clearly shows "BUILD FAILED" with error: "cordova-build error : java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0"Snixtor
It's a JDK version mismatch problem. Please override your JDK under VS->Tools->Options->Tools for Apache Cordova->Environment Variable Overrides->Override Java Home to your local JDK 1.8 Folder.Elvis Xia - MSFT
Just had the same situation. Elvis Xias Comment was the solution.Karl

5 Answers

7
votes

Install Java JDK 8.

Then, go to Tools-> Options ->Tools for Apache Cordova-> Environment Variable Overrides and set the path to your JDK to "C:\Program Files\java\jdk1.8.0_92" to get Java 8 instead of Java 7.

2
votes

I had the same problem. If you are using Android SDK Build-tools version 24.x just uninstall it and install version 23.0.3 from the Android SDK Manager.

1
votes

Download Java SE Development Kit 8u101 from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Go to Tools-> Options ->Tools for Apache Cordova-> Environment Variable Overrides and set the path to your JDK to "C:\Program Files\java\jdk1.8.0_101" to get Java 8 instead of Java 7.

0
votes

I can't add a comment due to the SO reputation rules, so I'll add "an answer" that Linda Z's comment should be marked as the answer.

I'm using Visual Studio 2015 with update 3, on a Windows 7 pc. I had the following error when trying to deploy (F5 - with Device selected) to my connected android phone

MSBUILD : cordova-build error : java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

I tried Linda's answer and it fixed the error and the app loaded onto the android phone. Thanks Linda Z.

0
votes

In addition to the answer from Linda Z:

You may also need to change your system's PATH environment variables to change from the Java 1.7 path to "C:\Program Files\java\jdk1.8.0_92\bin".

I needed to do this in spite of having the correct (1.8) Cordova JAVA_HOME path set in VS.