Gradle: Command failed with exit code 126

#1

Hello everyone,

I’m getting the following error when running ‘ionic cordova run android’

ANDROID_HOME=/home/nathan/Android/Sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
studio
/usr/lib/gradle/4.8.1/bin/gradle: 172: exec: : Permission denied
(node:7996) UnhandledPromiseRejectionWarning: Error: /usr/lib/gradle/4.8.1/bin/gradle: Command failed with exit code 126
    at ChildProcess.whenDone (/home/nathan/Workspace/demos/studentsapp-ionic/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:7996) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7996) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Does anyone know how to resolve?

Thanks in advance

my ionic info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.11
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v8.10.0
    npm               : 6.1.0 
    OS                : Linux 4.15

Environment Variables:

    ANDROID_HOME : /home/nathan/Android/Sdk

Misc:

    backend : pro
#2

I see you’re working on a Linux machine but this is what I do on my Windows machine. May it can give you some new insights…

Every time i get some gradle errors, first thing I do is deleting the .gradle folder in my user directory. (Asuming your setup doesn’t depend on other software and/or packages; please check your own other dependencies first.!)

  1. Close all running applications
  2. Navigate to C:\Users\ [USERNAME] in explorer
  3. Delete the .gradle folder and it’s content (you may need to logoff and login to release some running processes; if so, try this step again)
  4. Open Android Studio. Create a new empty project or open an existing project. When loading the project Android Studio willl download and prepare all required files and it will create your .gradle folder again.
  5. You may also need to delete and re-create your existing platforms (e.g. android).
  6. Try running ionic cordova run android again (console might download some dependencies again)

Building the first time after these steps does also fail with me again, but after trying again the building does succeed. (Just had to do this today again; working)

Hope you or others can do something with this…

cli packages: (C:\Users\admin\AppData\Roaming\npm\node_modules)
    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:
    cordova (Cordova CLI) : 8.0.0

local packages:
    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:
    Android SDK Tools : 26.1.1
    Node              : v8.9.1
    npm               : 5.8.0
    OS                : Windows 10

Environment Variables:
    ANDROID_HOME : C:\Android\sdk

Misc:
    backend : pro
#3

Thanks for your reply, I might be able to do something like that on my machine. :slight_smile:

#4

I found the problem, by accident. I was doing some random bs, like installing yarn. It gave me a message about unnecessary packages, one of them being gradle 4.8.1, and I knew Gradle 4.9 was also installed. So I runned apt-autoremove, tried to build, cordova decided to use gradle 4.9 by default and my app started.