zoukankan      html  css  js  c++  java
  • 解决 '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
    '"
     
  • 相关阅读:
    jdk环境变量配置(默认安装在c盘下)
    Less使用笔记
    Bootstrap4元素显示和隐藏
    npm常见命令及参数用法
    详解:cssrem插件 -- VS Code px转rem神器
    关于position:fixed的注意点
    解决:无法push到远程仓储
    解决:'git' 不是内部或外部命令,也不是可运行的程序
    小程序3-地图定位2
    转-前端开发流程
  • 原文地址:https://www.cnblogs.com/jeason1997/p/12410537.html
Copyright © 2011-2022 走看看