Apache Cordova – Set up Windows & Mac

I have finally entered the world of mobile app. Namely Cordova.  Before anything else … Its a pain. Nothing like elbow grease! For anyone reading this section, and you are starting out on your journey with hybrid-app, especially when you develop in Visual Studio. DONT DO IT.  Anyways as I learn the hard way, I thought VS can make the installation of packages easy, as it turns out It did not.

How to set up your Windows for Apache Cordova (Not in order)

  1. Install Node.JS,
    • Run npm install -g cordova
  2. Install Java (JDK)
    • Add the /bin folder to the PATH
    • Add a new environment variable named JAVA_HOME and set value to the JDK path.
  3. Install Gradle (https://gradle.org/install/)
    • Add the /bin folder to the PATH
  4. Install Android SDK (https://developer.android.com/studio/)
    • Add the [sdk folder]/tools folder to the PATH
    • Add the [sdk folder]/platform-tools folder to the PATH
    • Add a new environement variable named ANDROID_HOME and set the value to the SDK path folder.
  5. Then run “cordova requirements” to see whether you have installed everything right.
  6. Now you are ready to create your first mobile hybrid app using HTML/CSS/JS.
    • run “cordova create FolderName com.yourdomain.app MyAppName”

How to set up your Mac for Apache Cordova (Not in order)

  1. Check this link for detailed info: https://www.fiznool.com/blog/2017/05/29/a-guide-to-installing-cordova-on-your-mac/
  2. Install Xcode from the website or app store.
    • Run “xcode-select  –install” on the terminal. This will install cli for Xcode.
  3. Install Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  4. Install Android SDK https://developer.android.com/studio/index.html#command-tools
    • Extract the content(/tools) under /android anywhere in your drive system.
    • Run cmd
      • cd ~/android/tools/bin
        ./sdkmanager "build-tools;25.0.3" "emulator" "platforms;android-25" "platform-tools" "system-images;android-25;google_apis;x86" --verbose
        ./avdmanager -v create avd -n x86 -k "system-images;android-25;google_apis;x86" -g "google_apis"
    • This will generate /build-tools, /emulator, /platforms and /system-images.
  5. Install Gradle https://gradle.org/releases
    • Unzip the gradle content inside the android we created.
  6. Configure ANDROID_HOME env variable and PATH.
    • Open ~/.bash_profile and enter and save.
    • export ANDROID_HOME=$HOME/android
      export PATH=$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/gradle/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin
    • Depends where you extracted /android-sdk, /gradle and android tools.
  7. Install Cordova via NPM “npm install -g cordova”
  8. Install iOS-sim and iOS-deploy “npm install -g ios-sim ios-deploy” Lets you deploy to simulator and device.
  9. Then you can start creating projects using “cordova create myapp me.domain.myapp myapp”
  10. After you created your app and adding a iOS platform. You would build it “cordova build ios”. And the .xcworkspace in the platforms/ios/ folder must be opened in Xcode and you would build it from Xcode.

Notes: AVD Manager manages virtual devices while SDK Manager manages APIs currently installed on the system.

References:

https://docs.microsoft.com/en-us/visualstudio/cross-platform/tools-for-cordova/publishing/publish-to-a-store?view=toolsforcordova-2017

—-

Troubleshooting:

  1. Error: Cordova Could not reserve enough space for 2097152KB object heap

—-

Tips

  1. Run “cordova emulate android” to deploy application to virtual emulator device.
  2. If you are using AVD(Android Virtual Device). And run your emulator and get “PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT”. Set your environment to where your android-sdk is, and this should fix it. Note: You would need HAXM Accelerator and you will need Hyper-V disabled if you are using Windows. Download and install this in the SDK Manager.

And just bite on something and hope for the best. You will want look how to deploy and debug your app. I recommend using Visual studio code -> cordova plugin. It allows you to have a emulator for the browser to just hammer on development.

Good luck!

Leave a Reply

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