Ionic 3: Can't build Android since updating Cordova etc

My Ionic 3 project won’t build for Android any more. Serving to the browser is working. I’ve tried in numerous combinations:

  • removing android platform
  • updating cordova / ionic
  • re-adding platform
  • updating the already installed Android Studio SDK tools
  • head-butting the computer

I just can’t get it to build, not even the official Ionic docs have any info. Any ideas?

Note: There are loads of outdated answers on the net that haven’t worked, so please don’t just mark this as a duplicate, as the solution needs to be up to date.

Error message in console:

ANDROID_HOME=/Users/daveshirman/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
studio
(node:16020) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle 
in your path, or install Android Studio

Here’s my system version info:

Davids-MBP:apphazard-app daveshirman$ ionic info

cli packages: (/Users/daveshirman/Documents/Work/AppHazard/apphazard-app/node_modules)

    @ionic/cli-utils  : 1.19.1
    ionic (Ionic CLI) : 3.19.1

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.0.0
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.7.1

System:

    ios-deploy : 1.9.2 
    ios-sim    : 5.0.8 
    Node       : v6.10.0
    npm        : 3.10.10 
    OS         : macOS High Sierra
    Xcode      : Xcode 9.2 Build version 9C40b 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

I guess this is the issue + solution

So I did as the post suggested by doing the following in my project:

  1. ionic cordova remove platform android
  2. ionic cordova add platform android@6.4.0
  3. ionic cordova build android

…and am still getting the same build error as above.

Try to re-install Android Studio and android SDK?
Maybe that will fix the issue…

If that doesn’t work, start a brand new Ionic project and transplant your src folder and re-install plugins, npm packages.

Ok none of that worked. So I did the only thing I could think of - I grabbed the android sdk folder from a time machine backup that the error was complaining about being missing, now it builds.

I’ve probably got some sort of Frankenstein’s monster dev setup now, but I don’t care if the apps build and they work.

What a mess Ionic dev has become, it’s so sad.

Well at least my guess was correct. Something was wrong with your android SDK.

You’re running Node 6 and npm 3.

Update to the current Node LTS, and npm 5. Then reinstall Cordova 6.latest and see what happens.

Can you please post terminal commands here, as they will be useful if correct for others too. Thanks.

Terminal commands for what?

Updating Node LTS + NPm, just posting a sentence doesn’t help people who aren’t familiar with the correct commands to run.

I recommend you read the Wikipedia articles on NodeJS and npm. You don’t understand tools that are more fundamental to your setup than Ionic. There’s no terminal command to do what I suggested, unless you’ve already installed nvm, which I doubt.

1 Like

According to the error message:


Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio

So, I think you need to install gradle and setup the environment variables correctly.
I recommend SDKMAN to install but there are some more options: https://gradle.org/install/#install

If even after installing gradle you can’t get it working, try to open android studio and run a simple android project (some sample app). Android studio probably will show more friendly error messages to you if there are any environment problem.