Ionic cordova build android fails

I am trying to run ionic cordova build android but its failing with below error:

PS C:\Users\Dell\Desktop\recipe> ionic cordova build android
? The Ionic CLI (local version) has an update available (3.7.0 => 3.9.2)! Would you like to install it? No
[INFO] Not automatically updating your CLI. You can update manually:

       npm install --save-dev --save-exact ionic@latest

Running app-scripts build: --build --iscordovaserve --nobrowser

[00:09:37]  build dev started ...
[00:09:37]  clean started ...
[00:09:37]  clean finished in 12 ms
[00:09:37]  copy started ...
[00:09:37]  transpile started ...
[00:09:43]  transpile finished in 5.09 s
[00:09:43]  preprocess started ...
[00:09:43]  deeplinks started ...
[00:09:43]  deeplinks finished in 127 ms
[00:09:43]  preprocess finished in 129 ms
[00:09:43]  webpack started ...
[00:09:44]  copy finished in 6.24 s
[00:09:59]  webpack finished in 15.82 s
[00:09:59]  sass started ...
[00:10:02]  sass finished in 3.59 s
[00:10:02]  postprocess started ...
[00:10:02]  postprocess finished in 7 ms
[00:10:02]  lint started ...
[00:10:02]  build dev finished in 24.82 s
> ionic cordova prepare
> cordova prepare
| Running command [00:10:09]  tslint: C:/Users/Dell/Desktop/recipe/src/pages/shopping-list/shopping-list.ts, line: 2
            All imports are unused.

       L1:  import { Component } from '@angular/core';
       L2:  import { IonicPage, NavController, NavParams } from 'ionic-angular';
       L3:  import { IngredientService } from "../../service/shopping-list";

[00:10:09]  tslint: C:/Users/Dell/Desktop/recipe/src/pages/edit-recipe/edit-recipe.ts, line: 3
            All imports are unused.

       L2:  import { IonicPage, NavController, NavParams, ActionSheetController, AlertController, ToastController } from 'ionic-angular'
;
       L3:  import { Recipe } from "../../models/Recipe";
       L4:  import { FormGroup, FormControl, Validators, FormArray } from "@angular/forms";

[00:10:09]  tslint: C:/Users/Dell/Desktop/recipe/src/pages/tabs/tabs.ts, line: 2
            All imports are unused.

       L1:  import { Component } from '@angular/core';
       L2:  import { IonicPage, NavController, NavParams } from 'ionic-angular';
       L3:  import { ShoppingListPage } from "../shopping-list/shopping-list";

[00:10:09]  lint finished in 6.88 s
√ Running command - done!

You have been opted out of telemetry. To change this, run: cordova telemetry on.
> cordova build android
× Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.

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


        You have been opted out of telemetry. To change this, run: cordova telemetry on.
        ANDROID_HOME=C:\Users\Dell\AppData\Local\Android\sdk
        JAVA_HOME=C:\Program Files (x86)\java\jdk1.8.0_144
        Subproject Path: CordovaLib
        Starting a Gradle Daemon (subsequent builds will be faster)

        FAILURE: Build failed with an exception.

        * What went wrong:
        Unable to start the daemon process.
        This problem might be caused by incorrect configuration of the daemon.
        For example, an unrecognized jvm option is used.
        Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.3/userguide/gradle_daemon.html
        Please read the following process output to find out more:
        -----------------------
        Error occurred during initialization of VM
        Could not reserve enough space for 2097152KB object heap


        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
        Error: cmd: Command failed with exit code 1 Error output:
        FAILURE: Build failed with an exception.

        * What went wrong:
        Unable to start the daemon process.
        This problem might be caused by incorrect configuration of the daemon.
        For example, an unrecognized jvm option is used.
        Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.3/userguide/gradle_daemon.html
        Please read the following process output to find out more:
        -----------------------
        Error occurred during initialization of VM
        Could not reserve enough space for 2097152KB object heap


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

And this is what I get on running ionic info:

cli packages: (C:\Users\Dell\Desktop\recipe\node_modules)

    @ionic/cli-plugin-cordova       : 1.6.2
    @ionic/cli-plugin-ionic-angular : 1.4.1
    @ionic/cli-utils                : 1.7.0
    ionic (Ionic CLI)               : 3.7.0

global packages:

    Cordova CLI : 7.0.1

local packages:

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

System:

    Node : v6.11.2
    OS   : Windows 10
    npm  : 5.3.0

I have android studio already installed and I did build an app before this one. Why do I get error on this one. Can someone asssist.

Is cordova requirements happy?
Did you already built an app with Ionic CLI or with Android Studio?

This could mean is just couldn’t find enough free memory. Restart your computer and try again.

I got it solved. I changed gradle argument -Xmx20484m to 1024 or 512 at line:args.push(’-Dorg.gradle.jvmargs=-Xmx1024m’); in myproject file

platforms\android\cordova\lib\builders\GradleBuilder.js

1 Like