For AVD with 5.1.1 and 6.0, I used the following script in the windows:
set adb=adb -s emulator-5558 set arch=x64 set pie= adb start-server %adb% root %adb% remount rem %adb% shell mount -o remount,rw /system %adb% shell setenforce 0 %adb% install common/Superuser.apk %adb% push %arch%/su%pie% /system/bin/su %adb% shell chmod 0755 /system/bin/su %adb% push %arch%/su%pie% /system/xbin/su %adb% shell chmod 0755 /system/xbin/su %adb% shell su --install %adb% shell "su --daemon&" rem %adb% shell mount -o remount,ro /system exit /b
Need UPDATE.zip from SuperSU. Unzip them to any folder. Create a bat file with the contents above. Do not forget to specify the necessary architecture and device: set adb=adb -s emulator-5558 and set arch=x64 . If you run Android above or equal to 5.0, change set pie= to set pie=.pie . Run it. You get a temporary root for the current run.
If you encounter an error while rebooting the system partition, you need to start AVD from the command line. Below is the first step for Android 7.
If you want to make it permanent, update the binary in SuperSU and save system.img from the temp folder as the default replacement for system.img.
How to convert the resulting temporary root to permanent
Firstly, he goes to SuperSu. It offers a binary update. Update as usual. Reload reject.
The second is relevant only for emulators. The same AVD. The bottom line is that changes to the system image will not be saved. You must keep them for yourself.
There are already instructions for different emulators.
For AVD, you can try to find a temporary system.img file, save it somewhere and use it when the emulator starts.
On Windows, it is located in %LOCALAPPDATA%\Temp\AndroidEmulator and has a type name TMP4980.tmp .
You copy it to the avd device folder ( %HOMEPATH%\.android\avd\%AVD_NAME%.avd\ ) and rename it to system.img .
Now it will be used at the beginning, and not in normal mode. True, if the image in the SDK is updated, it will have the old one.
In this case, you will need to remove this system.img and repeat the operation when creating it.
A more detailed manual in Russian: http://w3bsit3-dns.com/forum/index.php?showtopic=318487&view=findpost&p=45421931
For android 7 you need to perform additional steps: 1. You need to run the emulator manually. Go to the sdk\tools\lib64\qt\lib folder. Run from this emulator folders with the parameters -writable-system -selinux disabled Like this:
F:\android\sdk\tools\lib64\qt\lib>F:\android\sdk\tools\emulator.exe -avd 7.0_x86 -verbose -writable-system -selinux disabled
You need to restart adbd from root:
adb -s emulator-5554 root
And remount system:
adb -s emulator-5554 remount
It can only be credited once per run emulator. And any other reboot may violate the recording mode. Because of this, you do not need to run any other commands with remount, for example mount -o remount,rw/system .
Other steps remain the same - load the binary, run the binary as a daemon, and so on.
Image from AVD Android 7 x86 with root: 
If you see an error in PIE when executing su binary, then you are loading the binary file incorrectly into the emulator. You should download the binary file named su.pie inside the archive, but on the emulator it should be named su , not su.pie .