Unable to build Cordova project in Visual Studio

2020-02-15 05:35发布

问题:

I'm using Visual Studio 2013 and the Cordova CTP 1.1. When I try to build the project, I get the following cryptic error (line breaks added for readability):

Error 22 
The command ""C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\vs-cli"
prepare --platform Android --configuration Debug
--projectDir . --projectName "servermon"" exited with code 8.
C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets 115 5 servermon

I've tried the solutions from this question as well as this question, and this doesn't appear to solve the issue. My system path appears to have everything relevant in it:

C:\Program Files\Java\jdk1.7.0_60\bin
C:\Users\Nathan\AppData\Local\Android\android-sdk\tools
C:\Users\Nathan\AppData\Local\Android\android-sdk\platform-tools
C:\apache-ant-1.9.3\bin
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
C:\Program Files (x86)\Windows Live\Shared
C:\Program Files\Microsoft\Web Platform Installer\
C:\Program Files (x86)\nodejs\
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ 

I've also opened up the SDK manager and made sure to get the latest (Rev 19) build tools. The system has been restarted more than once and I'm still not able to build. Does anyone have any ideas on how to fix this build issue?

Edit: Here is a screenshot of my SDK Manager

Edit2: Here is the build output

1>------ Build started: Project: servermon, Configuration: Debug Android ------
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript\Microsoft.TypeScript.targets(90,5): warning : The TypeScript Compiler was given no files for compilation, so it will skip compiling.
1>  Your environment has been set up for using Node.js 0.10.26 (ia32) and npm.
1>  ------ Ensuring correct global installation of package from source package directory: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\al3uox1v.u2n\packages\vs-mda
1>  ------ Build settings:
1>  ------    buildCommand: prepare
1>  ------    platform: Android
1>  ------    cordovaPlatform: android
1>  ------    configuration: Debug
1>  ------    cordovaConfiguration: Debug
1>  ------    projectName: servermon
1>  ------    projectSourceDir: C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest
1>  ------ App dir C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\bld\Debug already exists
1>  ------ Copying app files to www
1>  ------ Done copying app files to www
1>  ------ Copying res files
1>  ------ Done copying res files
1>  ------ Platform android already exists
1>  ------ Certificate copy from C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\res\cert\android to platforms\android
1>  ------ Done copying certificate files to platforms\android
1>  
1>  C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:126
1>                      throw e;
1>                            ^
1>  CordovaError: The provided path "C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\bld\Debug\platforms\android" is not an Android project.
1>      at Object.android_parser (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\metadata\android_parser.js:37:15)
1>      at C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\prepare.js:51:23
1>      at Array.map (native)
1>      at Object.prepare (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\prepare.js:49:35)
1>      at preparePlatform (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\app.js:322:24)
1>      at _fulfilled (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:787:54)
1>      at self.promiseDispatch.done (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:816:30)
1>      at Promise.promise.promiseDispatch (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:749:13)
1>      at C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:557:44
1>      at flush (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:108:17)
1>C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets(115,5): error MSB3073: The command ""C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\vs-cli" prepare --platform Android --configuration Debug --projectDir . --projectName "servermon"" exited with code 8.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

回答1:

It seems the Android template that was downloaded by Cordova is "corrupted".

To fix this: Try deleting the cached android platform in your user directory:

C:\users\<username>\.cordova\android\*

Then, clean and build the Solution in Visual Studio. Or to be really sure, delete the ‘bld’ directory inside the project folder.

This should force Cordova to re-download the Android template and fix the issue.



回答2:

for me I just deleted the bld folder and eveerything has become right



回答3:

Some time visual studio catch creates problem, clear the cache.

  1. Choose Tools, Options, Tools for Apache Cordova, and then choose Cordova Tools.

  2. Choose Clear Cordova Cache.

  3. Close and re-open your project.

  4. Choose Build, Clean Solution.