8

I'm trying to point an Android emulator to a local VM, for which I need to adb root. However, I'm getting this error:

$ adb root
adbd cannot run as root in production builds

Yet the build variant I am running of the p2p-app is debug:

enter image description here

The build.gradle for the p2p-app module includes the following:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable false
            signingConfig signingConfigs.release
        }

        debug {
            testCoverageEnabled = true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable true
            versionNameSuffix '-' + gitBranchName()
            applicationIdSuffix '.fifa'
            ext.betaDistributionReleaseNotesFilePath = "fabric-changelog.txt"
            ext.betaDistributionGroupAliases = "android-engineers"

        }
    }
}

Since the debug variant has debuggable true, I would expect it to be possible to get root access to the emulator?

Onik
  • 19,396
  • 14
  • 68
  • 91
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

2 Answers2

18

Following ADB root is not working on emulator, I managed to overcome this limitation by creating an emulator from a Google APIs system image, not a Google Play one (see screenshot below).

enter image description here

With this emulator I was able to adb root:

$ adb root
restarting adbd as root
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
4

The adb root shell command has nothing to do with any app's build variant. The command just tries to restart adbd (d stands for daemon) on a target device with root permissions. And it is a matter of the device (emulator) images build configuration to grant those.

In case of Android emulator configuration the root permissions cannot be granted. Moreover, it is totally redundant as both adbd and emulator's shell have elevated privileges compared to stock devices (a.k.a non-root).

In addition a very small extra explanation on differences between stock devices and emulators can be found here.

Onik
  • 19,396
  • 14
  • 68
  • 91