mercoledì 24 dicembre 2014

Apache Cordova development environment tutorial setup

This post will give you in a single place the list of steps you have to perform to setup a Apache Cordova environment with an Android emulator. Follow these steps if you are on Window 7.  There also explained some troubleshooting case I've done to get it working.

Apache Cordova is a platform for building native mobile applications using HTML, CSS and JavaScript

Prerequisite to download and install:

Java7 is required by Android Studio. Nodejs is necessary for server side mobile development but also brings the npm package manager to install Cordova and a lot more. Ant is required to build Cordova projects.Git client will for sure useful if you start learning more tutorial about cordova and mobile development.

After installing all make sure you add the new ANDROID_HOME and the update the PATH variable like these:

set ANDROID_HOME=C:\\dev\\tools\\Android\sdk
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\\sdk\\build-tools\\21.1.2;C:\\dev\\tools\\ant\\apache-ant-1.9.4\\bin;C:\\Users\\Administrator\\AppData\\Roaming\\npm;


1- Install Apache Cordova
C:\>npm install -g cordova
2- Create an HelloWorld app project:
C:\>cordova create hello com.example.hello HelloWorld
3- Install Apache Cordova Go in the hello directory and add the android platform for example:
C:>cd hello
C:\>cordova platform add android
If you get error like this:

Error: Please install Android target "android-19".
Hint: Run "android" from your command-line to open the SDK manager.

run the SDK Manager.exe from your ANDROID_HOME folder and make sure you install the SDK Platform for Android 4.4.2 (API 19). Once that is done you just rerun the cordova command above.

4- Build for Android
C:>cordova build android
5- Now before to run in the emulator to increase its speed ensure you have installed the x86 Intel Hardware Accelerated Execution Manager. To check browse the ANDROID_HOME files and open the SDK Manager to check if you have installed the extras package as in the picture below:



And then and run it form this directory: 

ANDROID_HOME\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm.exe

More details here: https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager

Note:  If during installation you get this error message below you will also need "Virtualization Technology" to be enabled on your BIOS.  For example in my Lenovo Thinkpad W530 VT-settings are located located under "Security | Virtualization", not under "CPU" settings. So google it for your computer.




After enabling BIOS acceleration, finally rerun again the program intelhaxm.exe. Instead if you get the error "VT not supported" during the installation disable Hyper-V on windows features. You can execute this command dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

6-Finally run the test android application
c:>cordova emulate android
The emulator will start and show the splashscreen of the default app just created. If size of the emulator does not fit correctly, close the emulator open the AVD Manager.exe and edit it:

This emulator size worked well on my screen :


Then finally you are ready with Cordova environment with an android emulator!
I suggest you at this point to learn more on developing Cordova with this very good tutorial:

https://ccoenraets.github.io/cordova-tutorial/index.html

Enjoy!

For official Apache Cordova documentation refer to:
http://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html#The%20Command-Line%20Interface
 add android

Nessun commento:

Posta un commento