我在Windows 7上为Android设置Cordova工作环境时遇到了一个问题。我使用NetBeans 8并遵循以下指南:链接这里新项目-> Cordova -> Hello World模板。
每当我试图建立一个Cordova项目(在NetBeans)我得到这个消息:
BUILD FAILED
C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidbuild.xml:90: Cannot find C:UsersAdministratorSkyDriveSkolegangDataingeniørAndroidadt-bundle-windows-x86_64-20130729sdktoolsantbuild.xml imported from C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidbuild.xml
Total time: 0 seconds
C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidcordovanode_modulesqq.js:126
throw e;
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidbuild.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidcordovarun.bat: Command failed with exit code 8
at ChildProcess.whenDone (C:UsersAdministratorAppDataRoamingnpmnode_modulescordovanode_modulescordova-libsrccordovasuperspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
Command finished with error code 8: C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidcordovarun.bat --emulator
C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2nbprojectbuild.xml:272: exec returned: 1
BUILD FAILED (total time: 47 seconds)
我在谷歌上搜索了几个小时,但似乎找不到解决方案。有些人会得到一些相同的错误(不完全相同,但相似),但解决方案不适合我。一个问题是关于Java 8和1.9.0以下的ant版本(我使用Node 0.10.26, Java 1.7.0_25, cordova 3.5.0-0.2.4和ant 1.9.4)。我还尝试使用控制台(CMD)创建一个新项目,但在构建时它给出了完全相同的错误。创建项目或添加Android平台都不是问题,问题在于如何构建项目。我认为环境变量设置正确,因为java, node, ant和cordova命令在cmd/powershell中工作得很好,check_reqs.bat
说环境很好。
就是这一行产生了错误:<import file="${sdk.dir}/tools/ant/build.xml" />
。这是消息的其余部分:Cannot find C:UsersAdministratorSkyDriveSkolegangDataingeniørAndroidadt-bundle-windows-x86_64-20130729sdktoolsantbuild.xml imported from C:UsersAdministratorDocumentsNetBeansProjectsHTML5Application2platformsandroidbuild.xml.
这是我在命令窗口(不使用NetBeans)中得到的错误:
PS C:UsersAdministratorDesktoptestfakeApp> cordova build android
Running command: C:UsersAdministratorDesktoptestfakeAppplatformsandroidcordovabuild.bat
Buildfile: C:UsersAdministratorDesktoptestfakeAppplatformsandroidbuild.xml
BUILD FAILED
C:UsersAdministratorDesktoptestfakeAppplatformsandroidbuild.xml:90: Cannot find C:UsersAdministratorSkyDrive
SkolegangDataingeni├©rAndroidadt-bundle-windows-x86_64-20130729sdktoolsantbuild.xml imported from C:UsersAdmini
stratorDesktoptestfakeAppplatformsandroidbuild.xml
Total time: 0 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,C:UsersAdministratorDesktoptestfakeAppplatformsandroi
dbuild.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: C:UsersAdministratorDesktoptestfakeAppplatformsandroidcordovabuild.bat: Command failed with exit code 2
at ChildProcess.whenDone (C:UsersAdministratorAppDataRoamingnpmnode_modulescordovanode_modulescordova-libs
rccordovasuperspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
我想也许这是一个路径问题,因为我在NetBeansProjects存储的路径中有一个特殊的字母(而且它也很长),但是在C:创建一个测试目录并使用命令窗口创建项目给出了相同的错误。我是新来的,所以我相信有一个简单的解决方案,提前谢谢。
我解决了这个问题,虽然我试图在OneDrive文件夹外创建一个cordova项目,但我没有想到SDK路径(也存储在OneDrive中)。通过将SDK文件移动到C:(路径可能不包含特殊字母'ø')并更改环境变量的路径(以及NetBeans中的SDK路径),它现在可以完美地运行。