Skip to content

Running Your Application

In this article, we will cover how to compile and run your app on a real device.

By the end of this article, you will have done the following,

Install Dependencies

Steps

  1. To install the project dependencies, while in your project directory run npm install.
cd hamv_mobile
npm install

Tip: You can now preview the app in a browser using ionic serve.

ionic serve

Note, this runs in debug mode with error handling, but most logs can be ignored at this time. Your browser should open automatically once the application is ready. If not, in your browser open http://localhost:8100/

Build the Platforms

Steps

  1. Before adding a platform, you must have an Ionic account. To sign up for an Ionic account, run ionic signup and follow the steps on screen.

    ionic signup
    

  2. Now you can create an Android/iOS project using ionic cordova platform add android or ionic cordova platform add ios.

    • Android (Please run the following one by one)

    ionic cordova platform add android
    
    After the “ionic cordova build android --prod --release”, add these lines:

    sed -i 's/defaultBuildToolsVersion="29.0.2"/defaultBuildToolsVersion="30.0.2"/g' platforms/android/build.gradle
    sed -i 's/defaultTargetSdkVersion=29/defaultTargetSdkVersion=30/g' platforms/android/build.gradle
    sed -i 's/defaultCompileSdkVersion=29/defaultCompileSdkVersion=30/g' platforms/android/build.gradle
    sed -i 's/target=android-29/target=android-30/g' platforms/android/project.properties
    sed -i 's/target=android-29/target=android-30/g' platforms/android/CordovaLib/project.properties
    
    • iOS
    ionic cordova platform add ios
    

Note

The first platform installation may take awhile to set up. (Estimated time: 15-20 minutes)

Congratulations! Your Ionic project is now ready to run on your phone.

Run the App on a Phone

Run on Android

Steps

  1. Install Android Studio. https://developer.android.com/studio/index.html

  2. Modify your bash file (Optional).

    • For Linux: Modify your .bashrc file and add below content.
    • For Mac: Modify your .bash_profile file and add below content.
    export PATH=${PATH}:\~/Library/Android/sdk/tools:\~/Library/Android/sdk/platform-tools:\~/Library/Android/sdk/tools/bin
    
  3. Install the Android SDK (See Android Cordova)

    To install, open the Android SDK Manager (run android or sdkmanager from your terminal) and make sure the following are installed:

    • Android Platform SDK for your targeted version of Android
    • Android SDK build-tools version 19.1.0 or higher
    • Android Support Repository (found under "Extras")
  4. Enable USB debugging and Developer Mode on your Android device, then run ionic cordova run android --prod --device from your terminal.

    ionic cordova run android --prod --device
    

    To only build your app, run ionic cordova build android --prod

    ionic cordova build android --prod
    

Run on iOS

Steps

  1. Download Xcode from App Store and update to latest version.

    This software installation can take awhile to set up.

  2. Agree to the development license.

    sudo xcodebuild -license accept
    
  3. Install an iOS simulator running npm i -g ios-deploy ios-sim.

    npm i -g ios-deploy ios-sim
    
  4. Set up a developer certificate for your iOS app.

    (1) This requires free or paid Apple developer account. You can sign up here, https://appleid.apple.com/

    (2) Open ".xcworkspace" in Xcode. The file should be under/platforms/ios/.xcworkspace

    (3) Set a developer certificate for your app, as pictured below. Select your project in the left side menu, make sure you're in "General", then finally select your developer certificate under "Team", in the "Signing" section.

    (4) You can now close Xcode.

  5. Build your app by running ionic cordova build ios --prod -- --buildFlag="-UseModernBuildSystem=0" from your terminal.

    ionic cordova build ios --prod -- --buildFlag="-UseModernBuildSystem=0" 
    
  6. Reopen your ".xcworkspace" in Xcode, then connect your phone via USB and select it as the run target, as pictured below.

  7. You can now run your app on your phone by clicking the play button. Make sure your device remains USB connected and unlocked.

Have more questions? Submit a request

Back to top