Resources:
unzip supersu-v2.79-201612051815.zip -d SuperSU
Create a virtual device for the emulator using AVD Manager: Pixel XL, Android 7.1.1, API 25.
Start the virtual device with a writable system partition and with SELinux disabled:
./emulator -avd Pixel_XL_API_25 -writable-system -selinux disabled
Run adb as root:
adb root adb remount
Install Superuser.apk (found in SuperSU archive, common folder) on the device:
adb install common/Superuser.apk
Push su binary (found in SuperSU archive, x86 folder) on the device, in /system/xbin/:
adb push push x86/su.pie /system/xbin/su
Change permissions to su binary:
adb shell chmod 0755 /system/xbin/su
Set SELinux on permissive mode:
adb shell setenforce 0
Install su:
adb shell su --install
Run su as daemon:
adb shell su --daemon&
Open SuperSU application and let it update the su binary.
Restart adb as non-root.
adb unroot
Enter adb shell and then access root using su.
adb shell su
Check if packet routing is enabled and enable it:
sysctl net.ipv4.ip_forward sysctl -w net.ipv4.ip_forward=1