cordova失败,退出代码为2

时间:2014-04-06 21:56:49

标签: cordova ionic-framework

我正在构建一个离子/ angularjs / phonegap应用程序。我是前端开发的新手。我有一个package.json和一个bowser.json。在package.json中,在安装包之后,我运行“bower install”来安装所有的bower依赖项。我可以在www中运行python服务器并在chrome中查看应用程序。但是我无法在Android模拟器中运行。有人可以指导我吗?

修改

我在发布这个问题之后意识到离子已经带有角度,我应该使用它。也不需要bootstrap,因为离子是我需要的框架。只需要下划线。我会清理它。但我认为这与错误无关。

运行“ cordova build ”后出现错误:

BUILD FAILED
k:\android\sdk\tools\ant\build.xml:932: The following error occurred while execu
ting this line:
k:\android\sdk\tools\ant\build.xml:950: java.lang.ArrayIndexOutOfBoundsException
: 1
        at com.android.ant.DependencyGraph.parseDependencyFile(DependencyGraph.j
ava:180)
        at com.android.ant.DependencyGraph.<init>(DependencyGraph.java:54)
        at com.android.ant.SingleDependencyTask.initDependencies(SingleDependenc
yTask.java:87)
        at com.android.ant.AaptExecTask.execute(AaptExecTask.java:509)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
        at com.android.ant.IfElseTask.execute(IfElseTask.java:124)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.jav
a:396)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.apache.tools.ant.Main.runBuild(Main.java:851)
        at org.apache.tools.ant.Main.startAnt(Main.java:235)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 4 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,k:\tmp\angularToDo\p
latforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: cmd: Command failed with exit code 2
    at ChildProcess.whenDone (c:\Users\IBM_ADMIN\AppData\Roaming\npm\node_module
s\cordova\src\superspawn.js:112: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)

的package.json

{
  "name": "ionic-project",
  "version": "1.0.0",
  "description": "An Ionic project",
  "dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^0.7.1",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0",
    "karma": "~0.10",
    "protractor": "~0.17.0",
    "bower": "^1.3.1"
  },
  "scripts": {
    "postinstall": "bower install"
  }
}

Bower.json (我是从angularjs种子项目得到的)

{
  "name": "angular-seed",
  "description": "A starter project for AngularJS",
  "version": "0.0.0",
  "homepage": "https://github.com/angular/angular-seed",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "angular": "1.2.x",
    "angular-route": "1.2.x",
    "angular-loader": "1.2.x",
    "angular-mocks": "~1.2.15",
    "bootstrap" : "3.1.1",
    "underscore" : "1.6.0"
  }
}

5 个答案:

答案 0 :(得分:22)

@givanse - 我回答了我自己的问题,所以如果你有平台依赖(意思是代码你不想在平台/ android中放松),那么为了做一个干净的构建,我做了:

rm -r platforms/android/ant-build
rm -r platforms/android/assets
现在一切都很好。感谢。

答案 1 :(得分:7)

错误似乎是由在完成之前中止的构建引起的,使项目处于不一致状态。

如果您没有自定义平台代码,只需:

rm -r platforms/android/
phonegap run android

请注意,如果您使用的是版本控制工具,则可以轻松恢复平台(已提交)更改:

git checkout platforms/android/

答案 2 :(得分:2)

这是正确的&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 这是由cordova中断编译引起的,如下所示:

建立失败

~\sdk\tools\ant\build.xml:932: The following error occurred while executing this line:
~\sdk\tools\ant\build.xml:950: java.lang.ArrayIndexOutOfBoundsException: 1
        at com.android.ant.DependencyGraph.parseDependencyFile(DependencyGraph.java:180)
        at com.android.ant.DependencyGraph.<init>(DependencyGraph.java:54)
        at com.android.ant.SingleDependencyTask.initDependencies(SingleDependencyTask.java:87)
        at com.android.ant.AaptExecTask.execute(AaptExecTask.java:509)

Error: ~\platforms\android\cordova\run.bat: Command failed with exit code 8
    at ChildProcess.whenDone (~npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:135:23)

您通过将~\platforms文件夹重命名为其他内容(或只删除它)然后在cmd

中运行来修复它
cordova platform add android

然后

cordova run android

答案 3 :(得分:1)

在升级版本后发生了这种情况,经过一些谷歌搜索后,我找到了最好的解决方案,只需删除平台,然后使用新的CLI重新添加它:

cordova platform remove PLATFORM
cordova platform add PLATFORM

然后构建成功

答案 4 :(得分:1)

如果您仔细阅读了该消息,您将获得提示。它正在你的android-sdk目录中寻找 android.bat 所以你所要做的就是复制 android.bat 的位置并放入你的环境windows路径。< / p>

您可能还会出现退出错误一“1”,这是因为您更改或更新了您的java目录,因此请将您的环境路径添加到java \ bin目录中。