Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova fails with exit code 2

I am building an ionic/angularjs/phonegap app. I am new to front end development. I have a package.json and a bowser.json. In package.json, after installing packages, I run "bower install" to install all the bower dependencies. I am able to run a python server in www and see the app in chrome. I am however not able to run in the android emulator. Can someone please guide me?

EDIT

I realized after posting this question that ionic already ships with angular and I should just use that. Also don't need bootstrap as ionic is a framework I need. Just need underscore. I will clean it up. But I don't think any of this is related to the error.

Here is the error after running "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 (I got it from angularjs seed project)

{
  "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"
  }
}
like image 846
U-L Avatar asked Apr 06 '14 21:04

U-L


5 Answers

@givanse - I answered my own question, so if you have platform dependencies(meaning code you do not want to loose in platform/android), so to do a clean build, I did:

rm -r platforms/android/ant-build
rm -r platforms/android/assets

all is good now. Thanks.

like image 69
hani elabed Avatar answered Oct 31 '22 17:10

hani elabed


The error seems to be caused by a build that was aborted before it completed, leaving the project in a inconsistent state.

If you don't have custom platform code, simply:

rm -r platforms/android/
phonegap run android

Note that if you are using a version control tool, you can easily recover your platform (committed) changes:

git checkout platforms/android/
like image 37
givanse Avatar answered Oct 31 '22 17:10

givanse


THIS IS CORRECT>>>>>>>> this is caused by an interrupted compile in cordova and looks like this:

BUILD FAILED

~\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)

you fix it by renaming the ~\platforms folder to something else (or just removing it) then running in cmd

cordova platform add android

then

cordova run android
like image 36
Mr Heelis Avatar answered Oct 31 '22 15:10

Mr Heelis


This happened to me after upgrading versions and after some googling I found the best solution to just remove the platform and then re-add it with the new CLI:

cordova platform remove PLATFORM
cordova platform add PLATFORM

Then the build succeeds

like image 1
blnc Avatar answered Oct 31 '22 15:10

blnc


If you read carefully what the message you will get the hint. It is looking for android.bat in your android-sdk directory so all you have to do is copy the location of android.bat and put in your environment windows path.

You might also get exit error one "1" that is because you changed or updated your java directory so, add to your environment path the java\bin directory.

like image 1
Naiem Soliman Saad Avatar answered Oct 31 '22 16:10

Naiem Soliman Saad