Hello all,
Today I am going to show you how to develop for Android using Apache Cordova on my MAC. I will also follow here all pre-requirements as well as providing the most common errors in order to help you to reach your goal - launch your Android app on Mac.
So, the first thing is install the dependencies for it:
1-Node.JS
1.1-Download and Install Node.JS for Mac: https://nodejs.org/en/download/
1.2- Follow the steps and complete successfully your NodeJS installation.
2- Install Apache Cordova using npm.
4-Now the common issues you might have:
4.1- FIRST COMMON ERROR: ANDROID_HOME not defined:
The fix is make sure you have your Android-sdk installed and set as environment variable, check the next picture.
4.2- SECOND COMMON ERROR: Another very common issue is when you are developing for multiple emulators, sometime you are testing android and your environment platform is set for IOS as below - during cordova prepare command:
Error: The provided path "/blablabla/" is not a Cordova iOS project.
Fix:
The fix for this is just go to your project home folder and run these commands:
- cordova platform rm ios (to remove IOS)
- cordova platform android(to add Android)
Now your Error: THe provided path "blablabla" is not a Cordova iOS project is fixed.
4.3- THIRD COMMON ERROR:
Fix:Running command: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build [Error: Please install Android target: "android-22". Hint: Open the SDK manager by running: /Users/ThiagoGuimaraes/adt-bundle-mac/sdk/tools/android You will require: 1. "SDK Platform" for android-22 2. "Android SDK Platform-tools (latest) 3. "Android SDK Build-tools" (latest)] ERROR building one of the platforms: Error: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2 You may not have the required environment or OS to build this project Error: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2" F
Make sure you have all required Android packages installed on your MAC running the command:
- [ANDROID-SDK-HOME]/tools/android as below:
Command +P : Cordova Build should work fine now as below:
4.4- FOURTH COMMON ERROR:
During the cordova run command you hit error related of emulator such as:
/tguimaraesMacpro/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
ERROR : No emulator images (avds) found.
Fix:
To fix this one you must create an ADV running this command on your terminal window.
/us/local/Cellar/android-sdk.24.4.1_1/tools/android adv
Now, finally, you are good to run your cordova: run command.
Then......your app in Apache Cordova finally launched to the mobile universe!!!
Please, find more about Apache Cordova here:
Happy coding. I hope it helps you, and talk to you soon.
Thiago Leoncio.