曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
Android

Getting Root Privileges in the Android Emulator

Preface During Android development, programs often inevitably need to operate on content under system directories. Although Android's kernel is a Linux system, the way to switch to root in Linux is sudo root, but Android does not provide us with an su file. So we need to add the su file to the system that needs root, and also change the permissions of the su binary. Operation Steps Step 1 Start the emulator that needs to be rooted Step 2 In a directory with supersu.apk

曦远 (DealiAxy)约 9 分钟
目录10 个章节

Preface

During Android development, programs often inevitably need to operate on content under system directories. Although Android's kernel is a Linux system, the way to switch to root in Linux is sudo root, but Android does not provide us with an su file. So we need to add the su file to the system that needs root, and also change the permissions of the su binary.

Operation Steps

Step 1

Start the emulator that needs to be rooted

Step 2

In the directory that contains the supersu.apk file, execute the following command

$ adb -e install supersu.apk Install super.apk onto the emulator. After it is installed, do not rush to run this App

Step 3

$ emulator.exe -avd [模拟器名字] -writable-system Run the emulator in a writable manner. You should use this command in the tools directory under your sdk directory, because that is where the emulator.exe program is.


Step 4

Unzip the downloaded supersu.zip file. You can see that many of the folders inside contain su files. My emulator is Androidx86, so I found the su.pie file under the x86 folder. If your Android version is 5.1 or a system greater than version 5.1, using su.pie is more suitable than the su file and can avoid some unnecessary problems. Next you need to do the following

$ adb root

$ adb remount

$ adb -e push C:\SuperSU-v2.79\x86\su.pie /system/xbin/su

In the root state, adb remount means remounting the system partition to make the system partition writable again. Under normal circumstances, files under system are not allowed to be written to; they are read-only. Copy su.pie to the /system/xbin/su file by means of push

Note: if your Android emulator's system version is less than 5.1, you need to use the su binary, not su.pie

$ adb -e push C:\SuperSU-v2.79\x86\su /system/xbin/su

Step 5

Now we need to use adb to modify the permissions of the su binary in the emulator

$ adb -e shell

$ su root

$ cd /system/xbin

$ chmod 06755 su

If you find that through ls -l you see that your su file's permissions are rwsr_x_x, that means it has succeeded


Step 6

Now we need to install the su binary (I am not sure exactly where it is installed; maybe it is installed into supersu.apk? I don't know either) and set it as a background daemon

$ su --install $ su --daemon&

I have not carefully looked into the purpose of this step for now


Step 7

Set SELinux restrictions, mainly disabling SELinux. The specific place to execute this command is not particularly fixed, but it seems there is no problem executing it at the end

$ setenforce 0

At this point, my Android emulator seems to have completed rooting. Reopen the Android emulator, tap to run the supersu program (that is, the program just installed onto your Android system). After opening, it may prompt you to update; you can ignore it and use it directly. Then your system has been rooted, and you can perform some operations that involve the system.

Note

If when you finally tap the supersu App it prompts that the su file cannot be found, that means your su file may not match, or it is because you opened the supersu App before completing the su file setup. Haha, you can try uninstalling the supersu App and starting over from the beginning with the steps above.

_EOF_

Getting Root Privileges in the Android Emulator

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

一加3升级Android9-0的刷机折腾之路

前言 你能想象一个16年发布的手机,到现在三年了,从一开始的Android6.0到现在的Android9.0吗?这系统更新的周期,可以说是比较良心了~ 不过这次升级Android9.0 虽然说是官方给出的ROM包,不过还是有一些小坑的,折腾了一个下午和晚上才最终装上去,也可能是我太久没有刷机了,生疏了不少吧。 先放截图 系统镜像下载 首先去官方通道下载镜像: 官方的Android9.0现在出到第二

2021-12-18 · Android · 约 1 分钟

电脑上的安卓系统——PhoenixOS浅度体验

前言 其实这篇关于PhoenixOS的浅度评测在几个月前就准备发了,当时是刚看到新闻说Android 7.0 x86的正式版刚刚发布,于是就下载来安装一番,结果.....体验极差= =,只能用这4个字来形容,不过既然体验Android x86,就不能扫兴而归,所以就把国产基于Android x86深度定制而颇有名气的PhoenixOS安装体验一番。 本文不涉及如何安装,因为安装过程很简单,如果有需

2021-12-18 · Android · 约 1 分钟

Android-x86-7-1-稳定版初体验

前言 最近Android x86发布了7.1的稳定版本,作为一名~~伪极客~~,自然是要安装体验一下。 关于在电脑上可以用的Android系统,可能大部分人了解的都是 Remix OS 和 Phoenix OS 这两个。不过这两个也是基于Android x86的nightly版本构建的,还是原版的才原汁原味呐。 这里不得不吐槽一下,这个Android x86项目的官网真是简陋,只有这么一个捐赠的海

2021-12-18 · Android · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…