37

According to the documentation

We can run our android project on an emulator by:

cordova run android or

cordova emulate android

But how to run a project on a real android device?

thanks a lot

-EDIT-

adb devices list none..

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

4 Answers4

63

You can force the run on device like this

cordova run android --device

If you get an error message like "No devices found" then make sure that you have developer mode and USB Debugging enabled on the device and also run adb kill-server and then adb devices should list your device and cordova run android --device should work

For iOS you can run from macOS

cordova run ios --device

If it doesn't work, make sure you have ios-sim and ios-deploy installed and that you have your development certificate and a wildcard provisioning profile on your machine. You can open the .xcworkspace file on /platforms/ios/ and Xcode will help you to create the certificates and provisioning profiles when you try to run the app.

adam.baker
  • 1,447
  • 1
  • 14
  • 30
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • 1
    I tried, but an error installing the .apk on the device. Do I have to set up somthing first? thanks! – Toni Michel Caubet Mar 07 '15 at 18:08
  • 2
    Sorry for the delay `ERROR: Failed to launch application on device: ERROR: Failed to install apk to device: ERROR: Failed to deploy to device, no devices found. Error: /Users/toniweb/Proyectos/cordova/funcook/platforms/android/cordova/run: Command failed with exit code 8 at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23) at ChildProcess.EventEmitter.emit (events.js:98:17) at maybeClose (child_process.js:753:16) at Process.ChildProcess._handle.onexit (child_process.js:820:5)` – Toni Michel Caubet Mar 17 '15 at 18:20
  • Then the problem is your computer doesn't recognize the device. If you are using windows you have to install drivers (from google or de device vendor) – jcesarmobile Mar 17 '15 at 21:48
  • I am actually using Mac OS, and I have the `htc` software included... any thoughts? – Toni Michel Caubet Mar 18 '15 at 11:24
  • do you have the developer options activated on your phone? and the usb debuggin? – jcesarmobile Mar 18 '15 at 11:40
  • Yes to both, and `adb devices` list none.. ¿? – Toni Michel Caubet Mar 18 '15 at 12:03
  • then that's the problem. maybe this helps http://stackoverflow.com/questions/7135999/adb-not-finding-my-device-phone-macos-x – jcesarmobile Mar 18 '15 at 13:20
  • 1
    I just needed `adb kill-server` and `adb devices`, it listed the device and `cordova run android --device` runned on the device, thanks! – Toni Michel Caubet Mar 18 '15 at 14:40
  • For me, it wasn't enough to enable developer mode. I also had to turn on USB Debugging inside the developer settings. – d512 Apr 05 '18 at 21:13
  • @d512 thanks for the note, it happened to me the other day on a new device, I think USB Debugging was automatically enabled when you enabled Developer settings, but it isn't enabled now – jcesarmobile Apr 06 '18 at 09:36
3

If a real device is connected to your pc and it is recognized as well, you ca just use
cordova run android
and the app will start on your device. It worked for me.

Morry
  • 726
  • 4
  • 11
1

you can do

cordova run android

as documented here.

That did not work for me for some reason. so what I did was copy the apk to the device. install it. and use chrome's remote debugging . by goint to chrome://inspect in chrome.

Txugo
  • 5,008
  • 5
  • 33
  • 40
0

For some reason, running it up from the cordova directory speeds up the time it takes to run the app on the device.

If you're on Ubuntu:

$ cd /path/to/project/platform/android/cordova/
$ node run --device

For Windows:

> cd /path/to/project/platform/android/cordova/
> run --device
revliscano
  • 2,227
  • 2
  • 12
  • 21