cmd:命令失败,退出代码为2

时间:2015-07-25 17:45:29

标签: android cordova visual-studio-2015

我最近安装了Visual Studio 2015.我刚刚创建了新项目Installed> JavaScript> Blank App(Apache Cordova)。我选择了Android> Google-Android-Emulator平台。当我点击Google-Android-Emulator时,它会出现此错误" cmd:命令失败,退出代码为2 "。我已经搜索了很多,但解决方案不适用于我。

这是我的输出窗口结果

1>------ Build started: Project: BlankCordovaApp7, Configuration: Debug Android ------
1>  Your environment has been set up for using Node.js 0.12.4 (x64) and npm.
1>  ------ Ensuring correct global installation of package from source package directory: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\ApacheCordovaTools\packages\vs-tac
1>  ------ Name from source package.json: vs-tac
1>  ------ Version from source package.json: 1.0.0
1>  ------ Package already installed globally at correct version.
1>  ------ Cordova tools 4.3.1 already installed.
1>  ------ Build Settings:
1>  ------ Build Settings:
1>  ------    platformConfigurationBldDir: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\bld\Android\Debug
1>  ------    platformConfigurationBinDir: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\bin\Android\Debug
1>  ------    buildCommand: build
1>  ------    platform: Android
1>  ------    cordovaPlatform: android
1>  ------    configuration: Debug
1>  ------    cordovaConfiguration: Debug
1>  ------    projectName: BlankCordovaApp7
1>  ------    projectSourceDir: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7
1>  ------    npmInstallDir: C:\Users\Muzafar Khan\AppData\Roaming\npm
1>  ------    buildTarget: AndroidEmulator
1>  ------    language: en-US
1>  ------ Platform android already exists
1>  ------ Copying native files from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\native\android to platforms\android
1>  ------ Done copying native files to platforms\android
1>  ------ Updating plugins
1>  ------ Currently installed plugins:
1>  ------ Currently installed dependent plugins:
1>  ------ Currently configured plugins:
1>  ------ Preparing platform: android
1>  Generating config.xml from defaults for platform "android"
1>  Calling plugman.prepare for platform "android"
1>  Preparing android project
1>  Processing configuration changes for plugins.
1>  Iterating over installed plugins: []
1>  Writing out cordova_plugins.js...
1>  Wrote out Android application name to "BlankCordovaApp7"
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-hdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-ldpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-mdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-xhdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-hdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-ldpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-mdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-xhdpi\screen.png
1>  splash screens: [{"src":"res/screens/android/screen-hdpi-landscape.png","density":"land-hdpi","platform":"android"},{"src":"res/screens/android/screen-ldpi-landscape.png","density":"land-ldpi","platform":"android"},{"src":"res/screens/android/screen-mdpi-landscape.png","density":"land-mdpi","platform":"android"},{"src":"res/screens/android/screen-xhdpi-landscape.png","density":"land-xhdpi","platform":"android"},{"src":"res/screens/android/screen-hdpi-portrait.png","density":"port-hdpi","platform":"android"},{"src":"res/screens/android/screen-ldpi-portrait.png","density":"port-ldpi","platform":"android"},{"src":"res/screens/android/screen-mdpi-portrait.png","density":"port-mdpi","platform":"android"},{"src":"res/screens/android/screen-xhdpi-portrait.png","density":"port-xhdpi","platform":"android"}]
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-hdpi-landscape.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-hdpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-ldpi-landscape.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-ldpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-mdpi-landscape.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-mdpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-xhdpi-landscape.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-land-xhdpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-hdpi-portrait.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-hdpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-ldpi-portrait.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-ldpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-mdpi-portrait.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-mdpi\screen.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\screens\android\screen-xhdpi-portrait.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-port-xhdpi\screen.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-hdpi\icon.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-ldpi\icon.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-mdpi\icon.png
1>  deleted: C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-xhdpi\icon.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\icons\android\icon-36-ldpi.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-ldpi\icon.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\icons\android\icon-48-mdpi.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-mdpi\icon.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\icons\android\icon-72-hdpi.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-hdpi\icon.png
1>  copying image from C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\res\icons\android\icon-96-xhdpi.png to C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\res\drawable-xhdpi\icon.png
1>  Wrote out Android package name to "io.cordova.myapp236d7e"
1>  ------ Copied C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\bin\Android\Debug\VSBuildInfo.xml to platforms\android\assets\www\VSBuildInfo.xml
1>  ------ Building platform: android
1>  Debug
1>  ------ Build configuration options: --debug
1>  Running command: cmd "/s /c ""C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\cordova\build.bat" --debug""
1>  Command finished with error code 2: cmd /s /c ""C:\Users\Muzafar Khan\Documents\Visual Studio 2015\Projects\BlankCordovaApp7\BlankCordovaApp7\platforms\android\cordova\build.bat" --debug"
1>ERROR building one of the platforms : error : cmd: Command failed with exit code 2
1>  You may not have the required environment or OS to build this project
1>MDAVSCLI : error : cmd: Command failed with exit code 2
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

2 个答案:

答案 0 :(得分:1)

我有完全相同的问题!我认为空间角色可能是路径上的一个问题,但没有变化。我的日志:

1> Running command: cmd "/s /c "c:\BlankCordovaApp1\BlankCordovaApp1\platforms\android\cordova\build.bat --debug --buildConfig=c:\BlankCordovaApp1\BlankCordovaApp1\build.json"" 1> Command finished with error code 2: cmd /s /c "c:\BlankCordovaApp1\BlankCordovaApp1\platforms\android\cordova\build.bat --debug --buildConfig=c:\BlankCordovaApp1\BlankCordovaApp1\build.json" 1>ERROR building one of the platforms : error : cmd: Command failed with exit code 2 1> You may not have the required environment or OS to build this project 1>MDAVSCLI : error : cmd: Command failed with exit code 2

当我在cmd窗口上手动启动时,有点奇怪

c:\BlankCordovaApp1\BlankCordovaApp1\platforms\android\cordova\build.bat --debug --buildConfig=c:\BlankCordovaApp1\BlankCordovaApp1\build.json

,它运行良好,我的apk是在调试目录中创建的,所以我说可能问题来自" / s / c。似乎命令根本无法执行,但我被困在这里......

编辑&解决方案:我现在有更多信息。这似乎是由于缺乏堆内存:转到工具 - >选项 - >项目和解决方案 - >构建并运行,将MSBuild项目构建输出详细程度更改为Diagnostic。重建项目并从输出窗口发布文本。 我有

Error occurred during initialization of VM (TaskId:11) 1> Could not reserve enough space for object heap (TaskId:11)

检查您是否拥有相同的内容。如果是,只需通过安装64位版本的java来解决问题(要知道你的是64b,只需尝试java -d64 -version)。 事实上,这个问题已经解决了: Visual Studio 2015 RC & Cordova: Could not reserve enough space for object heap (solved)

您所要做的就是: - 如果你还没有安装64b版本的Java。 - 覆盖VS / Tools / Options / Tools中的Java主路径,用于Apache Cordova / Environnement变量Overrides / JAVA HOME。 例如,它对我来说现在是C:\ Program Files \ Java \ jre1.8.0_51。 (小心不要指向Program Files(x86))

它对我有用。

为了更进一步,您可能需要查看此页面,解释如何配置您的真实Android设备以进行调试:http://developer.xamarin.com/guides/android/getting_started/installation/set_up_device_for_development/

您可能需要为您的手机安装正确的USB驱动器,Google通用版不适用于所有人。那就是它!

答案 1 :(得分:0)

为cordova设置PATH不适用于环境变量。 在Visual Studio(2013或更高版本)中,您必须转到工具>选项>用于Apache Cordova的工具,并从那里设置android sdk路径。 我已经处理了这个错误,并发现有一个依赖关系检查器可以告诉您运行代码所需的所有内容。