SuperSU emulator root for Android system permissions

adbd cannot run as root in production builds emulator

In the process of android development, the program often inevitably needs to manipulate the contents of the system directory. Although the kernel of android is linux, the way to switch to root in linux is sudo root, but in android, it does not provide us with su file.
So we need to add the su file to the system that needs root, and change the permissions of the su binary at the same time.

Raw materials



Step by step


Step 1

Run the emulator that needs root

Or just use the third step to start, otherwise you have to turn off the simulator after the second step.

Step 2

Execute the following command in the directory with the supersu.apk file

$ adb -e install supersu.apk
Install super.apk into the simulator, don't rush to run this app after installation

Step 3

The emulator name can be viewed using emulator -list-avds

$ emulator.exe -avd [emulator name] -writable-system

To run the emulator in a writable way, you should use this command in the tools file directory under your sdk directory, because there is only the emulator.exe program under this, and I will be pitted
. In fact, you only need to configure it. adb environment, do not need such trouble, directly emulator -avd {name} -writable-system

Step 4

Unzip the downloaded supersu.zip file and you can see that there are many folders containing su files. My emulator emulator is Android x86, so I found the su.pie file under the x86 folder. If your android version is 5.1 and greater than 5.1 , using su.pie is more suitable than su file , which can avoid some unsafe Necessary issues
In addition, x86_64 is x64, not x86.
If there is no su.pie in the folder, there is no need to find it.

Next you need to do the following

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

Adb root in the state remount mean remount the system partition , the system partition to re-write, system file the following general does not allow read-only. Copy su.pie to / system / xbin / su by push

Note: If the system version of your android emulator is less than 5.1, you need to use the su binary instead of su.pie, use the following command:

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

Step 5

Now we need to get the permission to modify the su binary file in the simulator through adb

$ adb -e shell
$ su root
$ cd / system / xbin
$ chmod 06755 su

If you find that the permissions of your su file are seen through ls -l, it rwsr_x_x has been successful

Step 6

Now we need to install the su binary and set it as a background daemon

$ su --install
$ su --daemon &

Step 7

Set the limit of SELinux, mainly to turn off SELinux, the specific execution location of this command is not specifically fixed, but it seems that there is no problem in the final execution

$ setenforce 0

At this point, my android emulator seems to have finished rooting, reopen the android emulator, click to run the supersu program (that is, the program just installed in your android system), open it and maybe it will prompt you to update, you can directly Ignore direct use. Then your system has been rooted and you can do some operations related to the system.

note:

1. If you are prompted to find the su file when you click the supersu App at the end, your su file may not match, or you opened the supersu App without completing the su file settings. Haha, you can try uninstalling the supersu App and restarting the above steps from scratch.

2. After the root simulator, if it is AVD Managercreated, you may encounter that it cannot be used AVD Managerto start again. At this time, you need to use the command to start

$ emulator.exe -avd [emulator name] -writable-system

Yes, and the third step is the same. Then if you close the command line hmmm... Well, the simulator is off.

Related Posts

Subscribe Our Newsletter