92

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.enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
guness
  • 6,336
  • 7
  • 59
  • 88

5 Answers5

285

To enable root access: Pick an emulator system image that is NOT labelled "Google Play". (The label text and other UI details vary by Android Studio version.)

Exception: As of 2020-10-08, the Release R "Android TV" system image will not run as root. Workaround: Use the Release Q (API level 29) Android TV system image instead.

Test it: Launch the emulator, then 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

Alternate test: Run adb shell, and if the prompt ends with $, run su. It should show 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, and click Next.
  4. Select a System Image.
    • Pick any image that does NOT say "(Google Play)" in the Target column.
    • If you depend on Google APIs (Google Sign In, Google Fit, etc.), pick an image marked with "(Google APIs)".
    • You might have to switch from the "Recommended" group to the "x86 Images" or "Other Images" group to find one.
  5. Click the Download button if needed.
  6. Finish creating your new AVD.
    • Tip: Start the AVD Name with the API level number so the list of Virtual Devices will sort by API level.
  7. Launch your new AVD. (You can click the green "play" triangle in the AVD window.

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

Jerry101
  • 12,157
  • 5
  • 44
  • 63
  • 17
    `su` gives me "su: not found" – Chad Bingham Nov 30 '18 at 21:12
  • 2
    How do I install a `Google APIs Intel x86 Atom System Image`? – Roni Castro Dec 05 '18 at 13:21
  • 2
    @RoniCastro I added the steps to do it. – Jerry101 Dec 05 '18 at 18:15
  • @ChadBingham are you sure you were not running a "Google Play ... System Image"? – Mattia Baldari Mar 19 '19 at 09:40
  • 1
    Thanks mate, I was like reaching nowhere with the sqlite debug, the old system image such as intel x86 works in emulator debugging. I had to restart adb as root using the command "adb root" to get access to the root folders. – Saravana Kumar K R Apr 25 '20 at 18:40
  • Thу above solution works for Phone/Tablet emulator. Is there a solution for Android TV emulator? The only available ATV image in SDK Manager is Android TV Intel x86 Atom System Image. I've created ATV emulator using this image, and "adb root" returns "adbd cannot run as root in production builds" error. @Jerry101, could you please help - is there a way to root ATV emulator? – Darkmike Oct 08 '20 at 10:19
  • 1
    @Darkmike the current Release R Android TV system image won't run as root, so use the Release Q (API level 29) Android TV system image instead. – Jerry101 Oct 08 '20 at 20:02
  • Where do you run `adb root` – Marcelo Gazzola Mar 23 '21 at 00:15
  • @MarceloGazzola you run `adb root` in your development computer's shell, assuming the Android SDK is installed and its `adb` executable is on your shell PATH. – Jerry101 Mar 23 '21 at 03:52
  • `To enable root access: Pick an emulator system image that is NOT labelled "Google Play"` For anyone that is wondering where this info came from. Here is the official documentation stating it: https://developer.android.com/studio/run/managing-avds#system-image – avelyne Aug 17 '22 at 16:09
  • What if I want to run adb root on an image with Google Play? Is there way to do so? – Itayst Nov 02 '22 at 13:35
  • @Itayst AFAIK there's no way to run adb root on an image with Google Play. – Jerry101 Nov 03 '22 at 01:09
12

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.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • 1
    I have just created an emulator from Android Studio menu, just as I did before. – guness May 18 '17 at 08:03
  • Perhaps not exactly as before, try an image with no Google API – Diego Torres Milano May 18 '17 at 16:04
  • debug builds also have Google API. – guness May 18 '17 at 19:55
  • 25
    @guness on the "Select a system image page" you need to select an "Android X.X (Google APIs)" image from the SECOND tab, NOT a "Android X.X (GooglePlay)" image from the first tab, which is what is selected by default. – Merk Jul 17 '17 at 22:44
  • With the Android Device Monitor packaged with Xamarin in VS2019 you have to untick "Google APIs" and "Google Play Store" (no tabs) then adb root works. – Alex Strickland Sep 04 '19 at 16:11
  • 5
    @Merk : I want to run playstore in emulator and also want root to work for research purpose. Is there any solution to this ? As of now, my only solution is one rooted device with playstore in it. – node_analyser Sep 02 '20 at 13:19
2

Go to tools -> SDK Manager -> Android SDK -- Now In the first tab (SDK Platforms) first of all "select" show package details at the bottom of the page. Now Select "Google APIs Intel x86 Atom System Image" and unselect "Google Play Intel x86 Atom System Image". This emulator won't show "adbd cannot run as root in production builds". Google API's don't have play store app and it only has play services.

Anshul Agarwal
  • 1,513
  • 13
  • 17
  • 3
    Any solution to have playstore in emulator as well as root access in the same emulator ? I tried installing playstore (com.android.vending) into emulator (with Google API image) but no success. – node_analyser Sep 02 '20 at 13:29
1

I had such a problem because for some reason it was set by default in build.gradle file release build mode. This mode does not allow communicating with the virtual device as a root. Debug mode must be enabled

buildTypes {
      release {
         signingConfig signingConfigs.debug
      }
}

changed to

buildTypes {
    debug{
        debuggable true
    }
}

Then in the AVD Manager I deleted and re-created a new virtual device. Rebooted and everything worked, root access became available.

  • The error message `adbd cannot run as root in production builds` really ought to say "... production builds **of Android**". Making a debug AVD (Android Virtual Device) is the fix. Making a production build of your app is irrelevant. – Jerry101 Feb 25 '23 at 04:56
0

I faced the same problem and solved it by:

First thing: Go to tools => Android => SDK Manager => Android SDK --In (SDK Platforms). Select "Google APIs Intel x86 Atom System Image" and do not select "Google Play Intel x86 Atom System Image".

Second thing: create a new emulator "Do not select Google Play Store".