解决 'adb root' 时提示 'adbd cannot run as root in production builds'
测试手机是红米3s,刷了原生第三方rom,安卓9.0
在刷了magisk获取root权限后,adb调试无法获取root权限。
注意:
1.在手机上,装上安卓终端软件,直接在本地系统上root是可以的
2.远程调试,不管是有线adb还是wifi adb,都无法通过adb root提权,但是可以在进入shell后再通过su切换到root
谷歌了下,发现是安卓9的限制以及magisk的问题,
https://github.com/topjohnwu/Magisk/issues/425
解决方法1:
关闭magisk的hide模式,然后重启手机,解决。但也失去了hide功能
或者可以修改magisk的配置文件ro.debuggable为1,因为安卓9默认在正式版是不支持adb root的,需要手动打开
解决方法2:
adb shell su works but adb root does not
By design adb root
command works in development builds only (i.e. eng
and userdebug
which have ro.debuggable=1
by default). So to enable the adb root
command on your otherwise rooteddevice just add the ro.debuggable=1
line to one of the following files:
/system/build.prop
/system/default.prop
/data/local.prop
If you want adb shell
to start as root
by default - then add ro.secure=0
as well.
原理跟上面的一样,改debuggabel为许可。但这个方法我尝试了没效果
解放方法3:
重新编译adbd,修改为可以调试,比较高级,我就不尝试了。
Alternatively you could use modified adbd
binary (which does not check for ro.debuggable
)
From https://android.googlesource.com/platform/system/core/+/master/adb/daemon/main.cpp
#if defined(ALLOW_ADBD_ROOT) // The properties that affect `adb root` and `adb unroot` are ro.secure and // ro.debuggable. In this context the names don't make the expected behavior // particularly obvious. // // ro.debuggable: // Allowed to become root, but not necessarily the default. Set to 1 on // eng and userdebug builds. // // ro.secure: // Drop privileges by default. Set to 1 on userdebug and user builds.
解决方法4:
Launch a script as root through ADB
最简单不用修改任何文件的方法,直接在进入adb shell后,开启su
但对于某些特殊需求,比如需要在PC上写一个脚本,一开始获取root权限,然后逐条执行adb命令,就麻烦了
可以修改执行命令的方式,例如: adb shell "su xxx",这样就可以通过root权限执行xxx命令了
#执行多条命令 adb shell "su -c '命令1; 命令2'" #分行执行多条命令 adb shell "su -c ' 命令1; 命令2 '" #例子 adb shell "su -c ' cd data; cd data; ls '"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!