PhoneGap CLI usage, gradle memory error, Android Build Tools unfound, one step deployment to phone on USB

Hi guys, while using “Make Native App with PhoneGap CLI”, basically, I could not make it work (gradle memory error).

Having extensively studied PhoneGap CLI - NSB App Studio (which is an excellent article and took all day to install as was pretty much warned :-), I encountered a persistent Gradle Memory error (windows 7 32 bit) …

“Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap”

See Full “cordova emulate” output from IDE for ref [below] for all of the output from the NS IDE(while using “Make Native App with PhoneGap CLI”).

Much googling and visits to cordova stack overflow etc could not help (although many have had this problem before and found various solutions, none that worked for me). They prompted me to try setting windows environment variables to…

  1. GRADLE_OPTS=-Xmx512m
  2. JAVA_OPTS=-Xmx512m
  3. _GRADLE_OPTS=-Xmx512m
  4. _JAVA_OPTS=-Xmx512m

…The latter (with extra “_” preceding) was prompted by here. All seem to be ignored.

Any clues? How can I set the VM max heap size to way less than 2GB? How can I even turn off the Daemon? The various instructions here had no effect for me.

Incidentally, in PhoneGap CLI - NSB App Studio , it mentions “AVD Manager.exe” … I could not find that (as also noted here). That may have helped if I could find it.


[details=Full “cordova emulate” output from IDE for ref]ANDROID_HOME=C:\AAA\AppStudios4MobilePhones\Node_js_PhoneGapCLI
JAVA_HOME=C:\Program Files\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 The Gradle Daemon - Gradle User Guide Version 3.3
    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 The Gradle Daemon - Gradle User Guide Version 3.3
    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.
    [/details]
Other misc info

It may be noted that “Make Native App with PhoneGap Build”, is working fine. My only reason for pursuing CLI is to deploy quickly to my phones, and control install etc with adb (which is working well). If you are a newbie reading this, I suggest stick with “Make Native App with PhoneGap Build:slight_smile:

Update: I found gradlew.bat deep in my orojecr folder, and after playing around with that, I find the line

“%JAVA_EXE%” %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% “-Dorg.gradle.appname=%APP_BASE_NAME%” -classpath “%CLASSPATH%” org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

…and I note that %JAVA_OPTS% & %GRADLE_OPTS% are overridden by the last item %CMD_LINE_ARGS% which is why my defaults above get ignored. I can modify the above line by adding " -Dorg.gradle.jvmargs=-Xmx512m" (note space preceding, ignore quotes). And this solved my first problem! But…

A new problem was raised (in “cordova emulate” output from IDE after using “Make Native App with PhoneGap CLI”)…
“No installed build tools found. Install the Android build tools version 19.1.0 or higher.”

Of course they are installed according to Android Studio (to see screenshot, click arrow)

…Any thoughts?

Hope this helps someone … the second problem I raised was because I had much earlier installed gradle manually. In doing so, as instructed by that installer, I had added a Local gradle path statement to the $path$ environ variable in my account (as opposed to system). I removed the Local paths and all was fine … it now produces an APK file.

There were a number of clues given to reolving this here: cordova - ionic build Android | error: No installed build tools found. Please install the Android build tools - Stack Overflow

Good work.

Do you have suggestions on how the tech note could be improved, so
others do not have to go through what you did?

Thanks! In answer, not really. Had my PC been clean, 64 bit with 4G+ ram, and had I followed your tech note to the letter, I’m sure it would have worked. I relied heavily on your technote and found no errors :slight_smile:

Perhaps, for those with 32 bit systems and not using AVD, some advice on how to change the memory as I achieved by modifying gradlew.bat (I have to use a 32bit W7 system to support my clients).

Question – can you advise what batch file calls gradlew.bat ? (Or is it called from within the IDE directly?). I’m trying to streamline the Make process. Cheers

Make files… It seems I can now answer my last query (what batch file calls gradlew.bat)…

It seems that “cordova” in Windows is just a batch file that calls Node (to compile I assume). In Windows, use where cordova (at the Cmd line) to find cordova.cmd. This can then be treated as a make file.

It’s easily edited and if you have set up the USB Android Device Bridge then, for example, you can add the following two lines after the Node call…

adb install -r -g "C:\AppStudioProjects\HelloWorldProject\phonegap\platforms\android\build\outputs\apk\android-debug.apk"
  adb shell monkey -p com.nsbasic.HelloWorld -c android.intent.category.LAUNCHER 1

…assuming you change \AppStudioProjects\HelloWorldProject and com.nsbasic.HelloWorld accordingly, this is tested on Android 7 to deploy and run quickly to a phone and it works well.

It’s a long road and a lot of setting up, but in the end well worth it. Once set up, in NSBasic, just do Alt+r, Alt+c (to do “Make Native App with PhoneGap CLI”) and watch as within seconds (about 10) the new app is running on your phone in the perfect test environment.

Type cordova at the Cmd line (dos box) to see the options. I also modified cordova.cmd to run cordova build instead of cordova emulate (replace %* with build). This removes the error report if you have removed the emulator (as I have) which NSB rightly say is not recommended.

Now if we could just couple that to the F5 function key… :slight_smile:

Thanks for posting this information. PhoneGap CLI is a lot harder to get up and running than PhoneGap Build, but it has some real advantages.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.