解決 '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
'"
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM