Rooting Android Emulator
Requirements:
Android Studio Installed
An Android Emulator running (for this tutorial version 5.1 -API 21-)
SuperSU Mobile app (chainfire)
Direct Download (called SuperSU APK)
Recovery flashable.zip
Direct Download (called SuperSU ZIP)
Alternative backup provided by XDA user Ibuprophen
Instructions
Install the SuperSu.apk
Install the SuperSu app firstly.
You can do it from the device from Google Play Store, or
Sideload through adb i.e
adb -e install supersu.apk
After installing it, when you run it shows a screen as shown below indicating "There is no SU binary installed..". This error just confirms the device is not yet rooted.
Make emulator’ system partition writable
As it suggests, we need to give the emulator permission to write system files.
List the emulators installed on your PC
emulator -list-avds

Navigate to the tools folder where Android SDK is installed and open command prompt there.
On Mac OS:
~/Library/Android/sdk/emulator
Type the following code to accomplish this:
emulator -avd {emulator_name} -writable-system

Pushing su binary in system directory
Extract the Recovery flashable.zip (containing the su binaries of different architectures)
Important! Only use the su binary that matches your AVD architecture e.g x86, arm etc.., and note the path where you extracted these binaries.

Make sure you are running adb as root and also you need to remount. Just enter these codes
adb root
adb remount

Now its time to push the su binary:

adb -e push adb -e push UPDATE-SuperSU-v2.82-20170528234214/x64/su /system/xbin/su
To figure out bin or xbin do in console before:
adb shell
ls /system/xbin/su
Change permissions of the su binary
Next let's do a bit of modification of the permissions of su binary. We have to do this in emulator device through adb:
adb -e shell su root cd /system/xbin chmod 06755 su

Take note of su binary path (mine is /system/xbin
)
Setting the
install
directive on su binary and set adaemon
su --install
su --daemon&

Setting SELinux to Permissive (i.e turning off SE Linux)
Finally turn off selinux through this code:
setenforce 0
Open SuperSU app on the Mobile emulator and it may ask to update binaries, you can use Normal method.

Now you have an emulator with root!

Last updated