cordova run (in real) android device using command line?

43,759

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
43,759
Toni Michel Caubet
Author by

Toni Michel Caubet

Front end developer and wordpress lover; based in Mallorca, Spain. Founder @ Funcook

Updated on December 04, 2020

Comments

  • Toni Michel Caubet
    Toni Michel Caubet over 3 years

    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
    Toni Michel Caubet over 9 years
    thanks for writing, the thing is that if run this command, the emulator is executed..
  • Txugo
    Txugo over 9 years
    yes I had the same issue. I think because the target api was 19 instead of 21 (lolypop). check my updated answer for a plan B.
  • Toni Michel Caubet
    Toni Michel Caubet over 9 years
    I tried, but an error installing the .apk on the device. Do I have to set up somthing first? thanks!
  • Toni Michel Caubet
    Toni Michel Caubet over 9 years
    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/c‌​ordova/run: Command failed with exit code 8 at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-li‌​b/src/cordova/supers‌​pawn.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)
  • jcesarmobile
    jcesarmobile over 9 years
    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)
  • Toni Michel Caubet
    Toni Michel Caubet over 9 years
    I am actually using Mac OS, and I have the htc software included... any thoughts?
  • jcesarmobile
    jcesarmobile over 9 years
    do you have the developer options activated on your phone? and the usb debuggin?
  • Toni Michel Caubet
    Toni Michel Caubet over 9 years
    Yes to both, and adb devices list none.. ¿?
  • jcesarmobile
    jcesarmobile over 9 years
    then that's the problem. maybe this helps stackoverflow.com/questions/7135999/…
  • Toni Michel Caubet
    Toni Michel Caubet over 9 years
    I just needed adb kill-server and adb devices, it listed the device and cordova run android --device runned on the device, thanks!
  • d512
    d512 over 6 years
    For me, it wasn't enough to enable developer mode. I also had to turn on USB Debugging inside the developer settings.
  • jcesarmobile
    jcesarmobile over 6 years
    @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
  • Enrique René
    Enrique René almost 4 years
    I'm using cordova 9.0.0 and --device flag is needed to run in android device, in this case.