On Ubuntu you may be best off installing Node via nvm - this lets you switch Node versions, and makes the install a bit easier than the official installation route.

Install ionic:

npm cache clean
npm install -g cordova ionic # (If it throws an EACCESS error, run it again with sudo)

Install the npm required packages

sudo npm install -g gulp # (This will install gulp in a folder that should be in the PATH)

Native build dependencies for Windows

node-gyp requires native build tools for your platform. If you're developing on Mac or Linux, you'll probably have these already (refer to the docs if not), on Windows, run the following command as administrator (in cmd or Powershell):

npm install --global --production windows-build-tools

Push notifications for Mac

Phonegap plugin push 1.9.0 requires CocoaPods to work. The installation steps can be found in https://cocoapods.org/

E.g. in Mac OS X you have to run:

sudo gem install cocoapods
pod setup

Please note that for compiling the app in Mac you need to open the .xcworkspace file, more information here: MOBILE-1970

Clone the app base code

Setup the environment

Please, note that if you are creating a custom app with a custom URL scheme, you should edit the /package.json and /config.xml files and specify there your custom URL_SCHEME (replacing the existing value) and your GCMPN SENDER_ID.

If you get errors while building, please see the Troubleshooting section below.

If using Ubuntu you should install the packages: gradle and libgradle-android-plugin-java (and all its dependencies) to build.

Compiling using AOT

Angular has 2 ways of compiling: JIT and AOT. Running "ionic serve" or "ionic build" compiles using JIT by default, which is faster to compile but the app takes longer to start.

When building for release you should always compile using AOT, otherwise the app can take too long to start in some devices. The default AOT compiling causes some issues with the database activity and the Mobile support for plugins, so you have to modify a couple of files in order to make this work.

First you need to open the file: node_modules/@angular/platform-browser-dynamic/esm5/platform-browser-dynamic.js. Search the variable called "_NO_RESOURCE_LOADER", you'll see it has a function named "get" with this line:

We tried to replace the default loader with our own implementation, but we weren't able to make the compiler work so the only solution left was to modify the default one.

Now you need to open the file: node_modules/@ionic/app-scripts/dist/util/config.js. In that file you need to remove the context.isProd condition from the options runMinifyJs and optimizeJs. So the final code for that part should be like this:

We want to compile in production mode but without optimizing and minifying Javascript because that breaks our plugins support. However, Ionic doesn't let you do that, so the only option is to do this change.

With these changes done you can now compile using production mode:

npm run ionic:build ----prod

This command will generate the app files and put them inside www folder. If you now want to install that app in a real device you can run "cordova run android" or "cordova build ios" (please don't use "ionic cordova ..." or "ionic serve" because it will override your build files!).