ADB root is not working on emulator

2019-01-11 06:53发布

问题:

I have just updated emulator 26.0.3, now I cannot run adb root command for new created emulator.

the error shown is below:

adbd cannot run as root in production builds

I have killed and restart adbd like:

adb kill-server
adb devices

Nothing helps, any ideas?


I am not sure what is the difference and how to select different build but, if following settings are enabled while creating, then it has root.

回答1:

[Credit belongs to @Merk but this should be posted as an answer rather than a comment.]

To enable root access, use an emulator image like

Google APIs Intel x86 Atom System Image

not

Google Play Intel x86 Atom System Image

To test it, run adb root. It should say

restarting adbd as root

or

adbd is already running as root

not

adbd cannot run as root in production builds

Alternatively, to test it, run adb shell, and if the prompt ends with $, run su. You should get a # prompt.

Steps: To install and use an emulator image that can run as root:

  1. In Android Studio, use the menu command Tools > AVD Manager.
  2. Click the +Create Virtual Device... button.
  3. Select the virtual Hardware.
  4. Select the System Image. Pick any of these:

    Intel x86 Atom System Image

    Intel x86 Atom_64 System Image

    Google APIs Intel x86 Atom System Image

    Google APIs Intel x86 Atom_64 System Image.

    (Do NOT pick "Google Play ... System Image". Those are the ones that cannot run as root.)

  5. Click the Download button if needed.
  6. Finish creating your new AVD.
  7. Run your new AVD.


回答2:

You are using the wrong emulator image if you want root access. As the error message states, root is not allowed in production builds, use an userdebug build instead.