Loading...

Exporting your Ionic App for Android

Exporting your Ionic App for Android

So you’ve been playing with the Ionic framework and want to finally see what it looks like on your device. After all, styles, screen widths etc will be different for your chosen device. For this I’ll be focusing on building for Android, mainly because I only have an Android and you need to build iOS on a Mac, which I also dont have. We work with what we have.

Android Studio Installation:

First off, you will need to download and install Android Studio. If you’re working off a new laptop like I am, you may need to install the appropriate JDK as well. Next, if you haven’t already, you will need to install Cordova globally using npm install -g cordova. Once you’ve done that we will add the Android platform to the app using cordova platform add android, if you are running iOS replace android with ios. Now, if you are planning to release your app right away, you will want to disable the debugger plugin by using “cordova plugin rm cordova-plugin-console”, otherwise you may skip this step.

Configuring Android

If you were to run the cordova –release build android command you may be met with something like this:

Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: C:\Users\{User Name}\AppData\Local\Android\sdk\tools\templates\gradle\wrapper

followed by the path that it checked for. When you run into this on Windows you can solve the issue possibly by updating your SDK, or if the SDK looking for gradle in the wrong place you’ll need to update your system environment varible. These can be found at Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables. I had to set my ANDROID_HOME variable to C:\Android\sdk. Direct your variable to your corresponding path for your sdk.

Java Heap Issues

Despite my laptop having 32GB of RAM I kept running into an issue after trying to build the app using the command:

cordova --release build android 

which would log out the following error:

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

This can be fixed by setting another System Variable by following the previous step via the Control Panel:

  • Variable name: _JAVA_OPTIONS
  • Variable value: -Xmx512M

Now, after all of those issues, if you run “cordova –release build android ” or “ionic build android” the process should now run unless you ran into any other problems? If so leave a comment, kind of want to document any other problems or issues with getting started.

Leave a Reply

Your email address will not be published. Required fields are marked *