Once you've built a project, the next logical step is to actually test it. To do this, you can deploy the code to a simulator (which is handy for debugging on your machine) or deploy the code to a device (which is a must to get a feel for how the app performs on a real device). You can do both using either CLIs, depending upon what the platform SDK supports. (For example, some platform SDKs may only support deploying to a simulator.)
If you need to deploy to the iOS simulator, you may need to install programs called ios-sim
and ios-deploy
.
To install both, just use the following commands from your command-line or terminal (wait for the first to complete before attempting the second):
sudo npm install -g ios-sim sudo npm install -g ios-deploy
Both CLIs can deploy your code to a device or simulator. If you need to test on iOS, keep in mind that iOS only permits deploying to the simulator as of Cordova 3.1. If you need to test on Android, it will normally depend on whether or not you have a device plugged in with USB debugging enabled and whether you are deploying the app to the simulator or a device.
The simplest method is to use the following pattern:
cordova emulate platform
To test on the Android simulator, you can type this:
cordova emulate android
To test on the iOS simulator, you can type this:
cordova emulate ios
Both options should launch the respective simulators and then launch the app. If you need to launch in a specific simulator, it's best to open the simulator manually and then deploy to the simulator.
You'll know things are working properly when you can see the app in the simulator. It should look something like this:
If you want to deploy to your Android device, plug it in first and then type the following command:
cordova run android
Wait a few moments and your device should begin running the app.
To deploy using the PhoneGap CLI, it's important to remember that this only works for local builds. If you built remotely, you need to navigate to http://build.phonegap.com and install from there.
To deploy to the iOS simulator, type this:
phonegap local install ios
To deploy to your Android device (be sure to plug it in) or simulator, type this:
phonegap local install android
You should see output similar to the following:
[phonegap] trying to install app onto device [phonegap] no device was found [phonegap] trying to install app onto emulator [phonegap] successfully installed onto emulator
If everything goes as it should, you should see the following image: