首页 > 解决方案 > 即使选择了“调试”构建变体,“adbd 无法在生产构建中以 root 身份运行”?

问题描述

我正在尝试将 Android 模拟器指向本地 VM,为此我需要adb root. 但是,我收到此错误:

$ adb root
adbd cannot run as root in production builds

然而,我正在运行的构建变体p2p-appdebug

在此处输入图像描述

该模块包括以下内容build.gradlep2p-app

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"

        }
    }
}

由于该debug变体具有debuggable true,我希望有可能获得对模拟器的 root 访问权限?

标签: androidandroid-emulatoradbroot

解决方案


ADB root is not working on emulator之后,我设法通过从Google API系统映像而不是Google Play映像创建模拟器来克服此限制(请参见下面的屏幕截图)。

在此处输入图像描述

有了这个模拟器,我能够adb root

$ adb root
restarting adbd as root

推荐阅读