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)
- Install Node.JS,
- Run npm install -g cordova
- 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.
- Install Gradle (https://gradle.org/install/)
- Add the /bin folder to the PATH
- 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.
- Then run “cordova requirements” to see whether you have installed everything right.
- 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)
- Check this link for detailed info: https://www.fiznool.com/blog/2017/05/29/a-guide-to-installing-cordova-on-your-mac/
- Install Xcode from the website or app store.
- Run “xcode-select –install” on the terminal. This will install cli for Xcode.
- Install Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- 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
./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.
- Install Gradle https://gradle.org/releases
- Unzip the gradle content inside the android we created.
- 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.
- Install Cordova via NPM “npm install -g cordova”
- Install iOS-sim and iOS-deploy “npm install -g ios-sim ios-deploy” Lets you deploy to simulator and device.
- Then you can start creating projects using “cordova create myapp me.domain.myapp myapp”
- 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.
- Error: Cordova Could not reserve enough space for 2097152KB object heap
- Solution: Is to add _JAVA_OPTIONS to the environment and set it to “-Xmx512M”
- Reference: https://stackoverflow.com/questions/41216921/cordova-could-not-reserve-enough-space-for-2097152kb-object-heap
- Run “cordova emulate android” to deploy application to virtual emulator device.
- 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.