ADB 根目录不能在模拟器上工作(不能在生产版本中作为根目录运行)

我刚刚更新了模拟器26.0.3,现在我不能为新创建的模拟器运行 adb root命令。

显示的错误如下:

adbd cannot run as root in production builds

我已经杀死并重启了 adbd,比如:

adb kill-server
adb devices

没什么有用的,有什么想法吗?


我不知道有什么区别,如何选择不同的建设,但, 如果在创建时启用了以下设置,那么它有 root.< img src = “ https://i.stack.imgur.com/bYXc5.png”alt = “ enter image description here”> < img src = “ https://i.stack.imgur.com/bYXc5.png”alt = “ enter image description here”>

81810 次浏览

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.

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.]

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.

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.

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".