Testing your application on real devices

Dear @max,

At the end of the first tutorial video LearnIonic you say that the best way to test/run your app would be if you connect a device.

Are there any guidelines/tutorials on how to do this, or is it just simply connect and run?

Thanks in advance!

1 Like

connect your device by usb. Then on your CLI try typing adb devices if a device is listed, run cordova run android.
If nothing appears on adb devices, go to settings on your phone, developer settings, and activate developer mode and usb debugging. You may need to re-plug your device after activating those settings.

This way you can test your app directly on your device.
For iphone just plug and cordova run ios

12 Likes

Thanks for you answer Iā€™m going to try it.

hiā€¦ Bonda it was not work for me, I attached my device and debug/usb conected fine, when I typing adb devices into command line showed : list of devices attached, thats all. When I run cordova run android have error no started emulator found, what happen ?

Are you using window machine for development,if so What android device are you using? is your device is showing in file explorer? if not install the device driver ,for samsung devices samsung kies,or other manufacturer install respective device driver.if you done those you can try the adb commands

D:\AndroidWorkSpace\My>adb devices
List of devices attached
0123456789ABCDEF        device

It will show the connected devices.

1 Like

Hi, Iā€™ve just documented how to view the console log on android:

Running logcat (see webview console log messages) on android

run ADB and get connected devices (first change dir to the android platform tools dir)

$ cd /Users/kevin/ADT/sdk/platform-tools

$ adb devices

List of devices attached
40CBA8038654 device

get PID (process ID) of app - first get all processes

$ adb -s 40CBA8038654 shell ps

then grep that (look for a string that identifies your app)
$ adb -s 40CBA8038654 shell ps | grep solomon (solomon being part of package name)
u0_a129 17099 151 363464 69256 ffffffff 00000000 S ie.solomon.myapp

$ adb -s 40CBA8038654 shell ps | grep 17099 (check for sub processes - so far iā€™ve found that the app runs as a single process)
u0_a129 17099 151 363464 69256 ffffffff 00000000 S ie.solomon.myapp

finally run logcat and filter by PID so you just see output from your app:

adb -s 40CBA8038654 shell logcat ā€“v time | grep 17099

For IOS, Iā€™ve found that once you have installed it via the USB, by doing cordova run ios, it will automatically provide a log

All this is on a Mac, but steps exactly same on Ubuntu (Linux). Of course IOS only works with a Mac

5 Likes

Hi Thamil thanks for your direction yes I am using windows, now my device showed in explorer, and do adb devices it is LJNJZPNJWWQ84AM device show up! but when I did cordova run android, this is another ERROR: failed to launch application on device: ERROR: failed to install apk to device: pkg: /data/local/tmp/cordovaApp-debug.apk do you have idea?

@vanbumi Great,I dont have the exact idea but. I Can suggest some tricks to find out the exact problem.

1.Manually copy your apk file to device /sd card or phone storage and install manually. if it is success it may be the problem in USB cable connection refer here

1 Like

Good manā€¦! I will try it for sure, thanks Iā€™ll let you knowā€¦ :slight_smile:

1 Like

Hi there

I am trying to run this on a USB connected ios device (iPhone 5) and whenever I run ios it opens the simulator on my computer, and nothing happens on my iPhone. Is there a step I might have missed.

Any help would be much appreciated - I am trying to test bluetooth connectivity and from my simulator I am just seeing that bluetooth is not enabled. I think this is because I am not testing on a real device.

Thanks
Josh

For iOS:
You need to build first the iOS-App

ionic build ios

Then go into your project folder and u see a ā€œplatformsā€ folder. In this folder u can see the platforms. Look in the iOS folder and open the xCode Project and then u can run your app on your iOS-Device.

INFO: You need a Provisioning-Profile, without this u cant build apps for your device!!!

For Android:
First look if you enabled Android-Development tool on your device. Then look in the Development-Tool, if USB-Debugging enabled!!!

After thees steps look into Security if is enabled to install apps from unknowns source.

If all enabled you can use in your terminal

ionic run android

Sorry for my bad english :S

3 Likes

Thank you, I solved my problem.

1 Like

You can also deploy to an android device connected to your local WiFi network. On most custom ROMs wifi adb is already built in and can be added to Quick Settings menu. It can also be enabled via Settings > Developer options ADB over network. If you donā€™t have the corresponding option then you can use a third party app which will let you turn it on and off. See e.g. https://play.google.com/store/search?q=wifi%20adb

Once you enabled ADB over wifi on the phone note down its IP address (e.g. 192.168.1.123), and then from terminal run:

adb connect 192.168.1.123

Now you can deploy directly to your phone without a cable:

ionic run android
1 Like

HI.
when I run ionic run android in terminal to run app in real device, I get the following error::

Running command: ā€œC:\Program Files (x86)\nodejs\node.exeā€ D:\wamp\www\pars-app\pars-app\hooks\after_prepare\010_add_platform_class.js D:\wamp\www\pars-app\pars-app

add to body class: platform-android

ANDROID_HOME=D:\Sdk\android-sdk

JAVA_HOME=C:\Program Files\java\jdk1.8.0_45

No target specified, deploying to emulator

ERROR running one or more of the platforms: No emulator images (avds) found. 1. Download desired System Image by running: ā€œD:\Sdk\android-sdk\tools\android.batā€ sdk 2. Create an AVD by running: ā€œD:\Sdk\android-sdk\tools\android.batā€ avd HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver

You may not have the required environment or OS to run this project

I am using windows 8 and Huawei with Android 4.2.2

Help Me Please.

adb devices just show emulator, not my connected device, why?

Xactly worked fine ā€¦

use this :

~ adb devices
~ adb kill-server
~ adb start-server
~ adb devices

you should now be able to see youā€™re connected device.

1 Like

Thank you. Yours method is working

@vanbumi please uninstall your already installed app with same package nameā€¦ then try to run.

Iā€™m facing same problem

Built the following apk(s):
E:/Aproject/Project file/thenationaltv app/mynationaltv/platforms/android/build/outputs/apk/android-debug.apk

native-run.cmd android --app platforms\android\app\build\outputs\apk\debug\app-debug.apk
No hardare devices found, attempting emulatorā€¦
Selected emulator emulator-5554
Error: ENOENT: no such file or directory, open ā€˜E:\Aproject\Project file\thenationaltv app\mynationaltv\platforms\android\app\build\outputs\apk\debug\app-debug.apkā€™
[ERROR] An error occurred while running subprocess native-run.

    native-run.cmd android --app platforms\android\app\build\outputs\apk\debug\app-d... exited with exit code 1.

    Re-running this command with the --verbose flag may provide more information.