无法使用Visual Studio在Android上构建(运行)Cordova应用程序

时间:2016-07-01 06:21:31

标签: android cordova visual-studio-2015 msbuild visual-studio-cordova

我创建了新的BlankCordovaApp,并且无法在Andorid上运行它,我在Windows上运行它没有任何问题。此外,我可以通过cmd手动构建和运行它:

 cordova run android

Visual Studio输出:

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输出:


    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 个答案:

答案 0 :(得分:7)

安装Java JDK 8.

然后,转到工具 - >选项 - > Apache Cordova工具 - >环境变量覆盖并将JDK的路径设置为" C:\ Program Files \ java \ jdk1.8.0_92"获取Java 8而不是Java 7.

答案 1 :(得分:2)

我遇到了同样的问题。如果您使用的是Android SDK Build-tools版本24.x,只需卸载它并从Android SDK Manager安装版本23.0.3即可。

答案 2 :(得分:1)

从中下载Java SE Development Kit 8u101 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 转到工具 - >选项 - > Apache Cordova工具 - >环境变量覆盖并将JDK的路径设置为“C:\ Program Files \ java \ jdk1.8.0_101”以获取Java 8而不是Java 7。

答案 3 :(得分:0)

由于SO声誉规则,我无法添加评论,因此我将添加“答案”,Linda Z的评论应标记为答案。

我在Windows 7电脑上使用Visual Studio 2015和更新3。我尝试部署(F5 - 选择了设备)到我连接的Android手机时出现以下错误

MSBUILD:cordova-build错误:java.lang.UnsupportedClassVersionError:com / android / dx / command / Main:不支持的major.minor版本52.0

我尝试了Linda的答案,它修复了错误并将应用程序加载到Android手机上。谢谢Linda Z。

答案 4 :(得分:0)

除了Linda Z的回答:

您可能还需要更改系统的PATH环境变量,以便从Java 1.7路径更改为" C:\ Program Files \ java \ jdk1.8.0_92 \ bin"。

尽管在VS中设置了正确的(1.8)Cordova JAVA_HOME路径,我还是需要这样做。