[ERROR] An error occurred while running cordova build android (exit code 1):

I am trying to build android and i am receiving the following error after i run : cordova ionic run android -verbose

Running command: sudo cordova run android -verbose


No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /Users/codehacker/Documents/projects/ionicProjects/newsApp/platforms/android/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/assets/www
Wrote out android application name "News App" to /Users/codehacker/Documents/projects/ionicProjects/newsApp/platforms/android/res/values/strings.xml
Wrote out Android package name "com.phatisa.newsapp" to /Users/codehacker/Documents/projects/ionicProjects/newsApp/platforms/android/src/com/phatisa/newsapp/MainActivity.java
Updating icons at platforms/android/res
Updating splash screens at platforms/android/res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
Running command: /usr/libexec/java_home
Command finished with error code 0: /usr/libexec/java_home
ANDROID_HOME=/Users/codehacker/documents/sdk/android
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
Running command: "/Applications/Android Studio.app/Contents/gradle/gradle-2.4/bin/gradle" -p /Users/codehacker/Documents/projects/ionicProjects/newsApp/platforms/android wrapper -b /Users/codehacker/Documents/projects/ionicProjects/newsApp/platforms/android/wrapper.gradle
Error: spawn EACCES

I currently have the following environment:

    @ionic/cli-utils  : 1.9.0
    ionic (Ionic CLI) : 3.9.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 ios 4.4.0
    Ionic Framework    : ionic-angular 3.6.0

System:

    ios-deploy : 1.9.1
    ios-sim    : 5.0.3
    Node       : v6.10.0
    npm        : 5.3.0
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b

iOS is building just fine but for some reason android is not working at all.

please help with this one, I have been bashing my head for the past 5 hours.

1 Like

Could you please post the real command you are executing with its full output and error? The one you posted is not possible.

Hi

Apologies for this, that was a case of poor copy and paste.
I have reposted the output along with the correct command i am running.

1 Like

You are posting at an Ionic forum, so you should use ionic cordova run android to make sure the Ionic app is built first.

You should also not need to add sudo in front of the command - if you have to this is a sign that stuff is broken and wrong.

The error message Error: spawn EACCES confirms this. The gradle command can’t be run because of some permission problem I think.

Additionally, run cordova requirements please.

1 Like

Hi , thanks for the feedback

I had issues with my permissions, hence why i was using sudo, however the ionic app seems to be building fine as per the output below from the second command.

I have run the 2 commands as advised following commands:

1: $ cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed Google Inc.:Google APIs:23,Google Inc.:Google APIs:22,Google Inc.:Google APIs:21,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:19,Google Inc.:Glass Development Kit Preview:19,Google Inc.:Google APIs:18,Google Inc.:Google APIs:17,Google Inc.:Google APIs:16,Google Inc.:Google APIs:15,Google Inc.:Google APIs:10,Google Inc.:Google APIs:8,android-25,android-24,android-23,android-22,android-21,android-20,android-19,android-18,android-17,android-16,android-15,android-10,android-8
Gradle: installed /Applications/Android Studio.app/Contents/gradle/gradle-2.4/bin/gradle

Requirements check results for ios:
Apple OS X: installed darwin
Xcode: installed 8.3.3
ios-deploy: installed 1.9.1
CocoaPods: installed

2: $ ionic cordova run android -verbose

[INFO] --consolelogs or --serverlogs detected, using --livereload
[INFO] Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 --serverlogs --nobrowser
       --iscordovaserve - Ctrl+C to cancel
[00:59:51]  watch started ...
[00:59:51]  build dev started ...
[00:59:51]  clean started ...
[00:59:51]  clean finished in 2 ms
[00:59:51]  copy started ...
[00:59:51]  transpile started ...
[00:59:53]  transpile finished in 2.33 s
[00:59:53]  preprocess started ...
[00:59:53]  deeplinks started ...
[00:59:53]  deeplinks finished in 59 ms
[00:59:53]  preprocess finished in 61 ms
[00:59:53]  webpack started ...
[00:59:53]  copy finished in 2.55 s
[01:00:01]  webpack finished in 7.66 s
[01:00:01]  sass started ...
[01:00:02]  sass finished in 1.05 s
[01:00:02]  postprocess started ...
[01:00:02]  postprocess finished in 4 ms
[01:00:02]  lint started ...
[01:00:02]  build dev finished in 11.14 s
[01:00:02]  watch ready in 11.20 s
[01:00:02]  dev server running: http://localhost:8100/

[INFO] Development server running
       Local: http://localhost:8100
       External: http://10.0.0.8:8100

> cordova run android
ANDROID_HOME=/Users/codehacker/documents/sdk/android
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
Error: spawn EACCES

[ERROR] An error occurred while running cordova run android (exit code 1).


Munyaradzis-MBP:newsApp codehacker$ (node:734) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: channel closed

You have this backwards. Using sudo caused your permission problems.

Okay…at this point i have no idea what the root cause is.

i went as far as creating a blank project without using sudo and i am still encountering the same issue.

What would you suggest i do?

I would start by uninstalling and reinstalling Android Studio. But, and I simply cannot stress this enough, when you run something under sudo, even once, there is nothing general anybody can say about what damage it has done and how to reverse it. So either you use tools like strace to track down and repair permissions on specific files, or you may end up having to simply nuke everything from orbit and reinstall the OS from scratch.

Well i don’t even use Android studio though, i had it before

Nuking the entire operating system seems a bit too drastic for me.

Your stacktrace begs to differ with you about that.

1 Like

I have uninstalled it, and i am still having the same issue

How is that possible, when the initial report specifically mentions Android Studio?

Not really, your stuff is fucked up and you have to find a way to fix it or your will spend the next few months with random errors like this one.

Get rid of Ionic, Cordova, npm, node, Android Studio, Android SDK.
Install nvm and install a new node.
Install Ionic and Cordova globally again.
Run cordova requirements and install everything it needs.
(Never use sudo here)

Thank you for your help, i think i found a solution.
See my updated question with the solution there.

Please post the solution as a reply so it can be selected as “this resolves the issue” and the topic be marked as “solved”.

SOLUTION

The issue had to do with the version of gradle i was running.
Thank to @rapropos for pointing me in the right direction, I was starting to lose my mind.The key was in the information i posted in the thread below:

Basically what i did was:

  1. Uninstalled Android Studio to remove gradle version was being used to build my app
  2. Reinstalled a new version of Gradle and updated my brew by running: brew update && brew install gradle
  3. In my project, i then forced a rebuild of my sass as the 2 were out of sync: npm rebuild node-sass --force
  4. Rebuilt the project, by running : ionic cordova build android

I hope this solution helps someone else and saves a few hairs in the process!! :slight_smile:

1 Like

This helped me as well…sudo is another name for the devil…lol :smile:
I got rid of all of them and did the following on my project folder:

sudo chown -R $USER /usr/local/
cd into <<AppFolder>> Parent
run: chown -R $USER <<AppFolderName>>

Maybe this was overkill but i wasnt taking any chances.
Perhaps this can help someone else

I would vote this a very bad idea. Instead, use nvm to manage node installations.

1 Like