Why is "adb install (my APK)" triggering "can't find service: package"?
Asked Answered
B

4

41

I am starting up an android virtual device, but I am getting:

Starting emulator for AVD 'avd.1'
pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
emulator: Listening for console connections on port: 5558
emulator: Serial number of this emulator (for ADB): emulator-5558

The emulator is coming up but I see no icons on it so I'm wondering if the errors listed above are "showstoppers"? Then when I try adb install bin/my.apk I get the error Can't find service: package. So it seems adb is not communicating with the AVD correctly. However, adb devices does show emulator-5558 listed above. Any advice would be really helpful.

Bertiebertila answered 17/3, 2017 at 23:25 Comment(6)
Were you able to resolve this?Protect
No - I had given up on getting an emulator going and am now developing off an actual device and looking at logs with adb. It would be nice to have the option of using an emulator though so if anyone has any ideas as to why (1) the emulated device would show on the screen with no icons and (2) why I would get a "can't find service" msg when trying "adb install", I welcome them. TIA.Bertiebertila
I created a new emulator with similar config after deleting and redownloading the images, and it worked this time. My guess is something was missing or misconfigured or corrupt in the older emulator config/image.Protect
Thanks adarsh. I'll try that.Bertiebertila
In my case, it looks like the error was due to the ARM emulator that was so slow that it had not time to load all services before I executed the adb install xxx.apk command. When I tried the command a second time, I got another error: adb: failed to install xxx.apk: without any information but I noticed that the app was installed correctly. You can see if the "package" service is loaded by typing the command adb shell service list.Monitory
Try running the install as root, ie 'sudo install bin/my.apk'. Had the same problem, this fixed it.Teodorateodorico
E
8

You have essentially answered your own question while asking it. The root of the problem is that the emulator is not setup properly (evidenced by the system UI not loading). When Android can't boot properly, it is likely to fail to start some system services (in this case, the package service).

The solution is to recreate the emulator, possibly with a different system image (in case the one you have been using is corrupt). If you are using an official image, try switching API levels, or switch from a GMS-enabled emulator image to a non-GMS image (or vice-versa).

Expellant answered 31/10, 2018 at 15:38 Comment(2)
thanks for that blufenix. I'll check out another image.Bertiebertila
This can also happen when messing around with -wipe-data or -no-snapshot flags with an emulator that previously had saved stateJaime
M
7

It also happened to me after closing the emulator while debugging. Yes, not the best idea...

The solution for me was:

  1. Click on Tools > AVD-Manager.
  2. Click on the arrow to bottom on the right of the new window from your (virtual) device.
  3. Click on "Cold Boot Now".

Screenshot

Mada answered 30/4, 2021 at 22:27 Comment(1)
Cold boot works, I wished Android Studio can give a more meaningful error.Renown
B
1

Don't forget to enable usb debug mode and in developer option to consent data file transfer, for me it solved this issue, hope this help

Bernardobernarr answered 2/4, 2021 at 22:38 Comment(0)
V
0

You can also get this fault when delpoying to physical devices. The solution is to restart the adb server, using:

adb kill-server
Vendue answered 12/12, 2022 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.