Trigger Errors when run with 'ionic cordova run android'

Hi all,

I’ve tried remove, add cordova android platform again and again. and even tried to uninstall, install the npm also.

This is my ionic info.

cli packages: (/usr/local/lib/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.1.8_
_ Cordova Platforms : android 7.0.0 ios 4.5.4_
_ Ionic Framework : ionic-angular 3.9.2_

System:

_ Node : v8.1.0_
_ npm : 5.0.3 _
_ OS : macOS High Sierra_
_ Xcode : Xcode 9.2 Build version 9C40b _

Environment Variables:

_ ANDROID_HOME : not set_

Misc:

_ backend : pro_

And this is my error.

FAILURE: Build failed with an exception.

*** What went wrong:**
Execution failed for task ‘:app:packageDebug’.
> Java heap space

*** Try:**
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

*** Get more help at https://help.gradle.org**

BUILD FAILED in 22s
(node:4060) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /Users/phyopwintthu/IonicProjects/macallan_apps/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

*** What went wrong:**
Execution failed for task ‘:app:packageDebug’.
> Java heap space

*** Try:**
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

*** Get more help at https://help.gradle.org**

BUILD FAILED in 22s
(node:4060) [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.

I’ve spent the whole morning solving this and still cannot done. Could someone help me please.

Environment Variables:
ANDROID_HOME : not set_

you should add ANDROID_HOME and JAVA_HOME in Environment Variables system path

I’ve set Android Home but I still got this error tho.

BUILD FAILED in 27s
(node:1289) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /Users/my_name/IonicProjects/prj_name/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

did you set gradle path in Environment Variables system path?

Yes, after I’ve add GRADLE_HOME/bin to environment variable. My error has been changed.
ionic serve is still working.

FAILURE: Build failed with an exception.

*** What went wrong:**
Execution failed for task ‘:app:packageDebug’.
> Java heap space

*** Try:**
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

*** Get more help at https://help.gradle.org**

BUILD FAILED in 19s
** at ChildProcess.whenDone (/Users/my_name/IonicProjects/app_name/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)**
** at ChildProcess.emit (events.js:127:13)**
** at maybeClose (internal/child_process.js:933:16)**
** at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)**
(node:6007) 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:6007) [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.