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
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.
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.
…
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: Gradle | Installation
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.