5

The Connected Device:

  • It is running Developer Options with USB debugging enabled

  • It is using MTP as the Device file manager

  • Drivers have been installed to the laptop with no issues and I can browse the files fine

When I run: ionic cordova run android --device I get this output:

BUILD SUCCESSFUL in 5s
42 actionable tasks: 42 up-to-date
Built the following apk(s):
    C:\Users\K-PC\myApp\platforms\android\app\build\outputs\apk\debug\app-debug.apk
native-run.cmd android --app platforms\android\app\build\outputs\apk\debug\app-debug.apk --device
[native-run] ERR_NO_DEVICE: No hardware devices found. Not attempting emulator because --device was specified.
[native-run]
[native-run]    More details for this error may be available online:
[native-run]
[native-run]    https://github.com/ionic-team/native-run/wiki/Android-Errors
[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.

I checked to see if the device was listed using native-run android --list and I get this output:

Errors (!):

  ERR_UNSUITABLE_API_INSTALLATION: No suitable API installation found.

        More details for this error may be available online:

        https://github.com/ionic-team/native-run/wiki/Android-Errors

Connected Devices:

  No connected devices found

Virtual Devices:

  No virtual devices found

I have Android Studio installed, I have two virtual devices in my AVD manager:

AVD Manager

I want to deploy the APK onto the device connected to my laptop, not these emulators but its strange to see that it hasn't even recognised the emulators inside my AVD manager

How can I fix this issue? I hope I have given enough detail.

Jaquarh
  • 6,493
  • 7
  • 34
  • 86

2 Answers2

6

Using ADB

adb devices

That command should give you a list of the attached devices. You must accept the debug mode on the phone. Before trying to run the app with a hardware device you should check that adb has a connection with one device atleast.Some issues may appear like:

  1. List of devices are empty: That means that the device is either not properly connected or there's an issue with the USB cable(may be broken).
  2. Unauthorized: Appears when you didn't accept the debug authorization of your phone.
  3. Offline: The phone has a little service called daemon that allows it to connect with the computer so can transfer the files and listen to changes. When this service is not running it stops the connection with the computer. Can be solved by rebooting the device or connect/disconnect the USB cable until it can be shown as "online".

In summary you should run this code:

  1. Enable Debug mode on your Android device. Also enable USB debug that is in the same configuration view.
  2. Run adb devices, Authorize to connect with the computer. Solve the issues(if there's any) already commented above.
  3. Run ionic cordova run android --device.
  4. Happy coding time!.
Jo Carrasco
  • 314
  • 3
  • 9
  • Nothing was shown which made me realise that USB debugging was not enabled correctly. I enabled it before I plugged the device in, which didn't allow me to add the device as a trusted computer. Thanks for this push to see that! – Jaquarh Jul 11 '20 at 08:34
  • When I type in 'adb devices' command it returns: 'bash: adb: command not found'. Can suggest what needs to be done? – Jayprakash Dubey Aug 10 '21 at 06:28
  • 2
    @JayprakashDubey You need to download the platform-tools from Android Studio Official website: https://developer.android.com/studio/releases/platform-tools. Then put that folder in C:\Users\{User Name}\AppData\Local\Android\sdk\platform-tools. Go to that platform-tools folder and try to run your commands in that folder. If you want to be able to execute that command anywhere, Add the platform-tools path to the "PATH" enviroment variable. Happy Coding! – Jo Carrasco Aug 14 '21 at 14:55
  • Restart with: `adb kill-server` and then `adb start-server` – Grant Nov 03 '21 at 08:42
6

I had the same problem.
I solved it like here: Ionic forum.

In the case that the command adb devices return a list of devices and emulators, but the command ionic cap run android --list not recognize these, the problem could be that required environment vars ANDROID_SDK_ROOT and ANDROID_HOME are not set.

$ adb devices
List of devices attached
817460470221    device
emulator-5554   device

$ ionic cap run android --list
[INFO] No native targets found.

To set this vars first found the android sdk location, for this you can go to android-studio and in the menu Tools > SDK Manager, search the section call Android Location, export both vars in the shell instance used to run the ionic commands.

In my case I did this

export ANDROID_SDK_ROOT="/home/myhome/Android/Sdk"
export ANDROID_HOME="/myhome/myhome/Android/Sdk"  
mustafa candan
  • 567
  • 5
  • 16