KernelSU Next AVD roots an Android Studio emulator (AVD) with KernelSU Next, loaded as a GKI kernel module. It's a pair of scripts you run on your computer: ksuAVD.bat for Windows and ksuAVD.sh for Linux and macOS. ymuuuu forked it from HChenX's KernelSU-AVD and switched it to KernelSU Next.
What's been tested
| Emulator | Result |
|---|---|
| Android 16 | Works, the only version confirmed end to end |
| Android 15 | Fails, with errors from KernelSU Next itself |
| Everything else | Untested |
Your ramdisk.img is backed up before anything is changed, so a failed attempt can be undone.
Before you start
- An AVD on a GKI kernel:
android12-5.10,android13-5.15,android14-6.1,android15-6.6,android16-6.12or newer, onx86_64orarm64-v8a. adbin yourPATH, or in the default SDK folder (%LOCALAPPDATA%\Android\Sdkon Windows,~/Android/Sdkelsewhere).- The emulator already running. Check with
adb devices.
Rooting the emulator
- Run the script with no arguments. It shows the emulator it found and prints a ready-to-paste command for every system image on your machine.
- Run one of those commands, or pass your own path to
ramdisk.img, for example./ksuAVD.sh "system-images/android-34/google_apis/x86_64/ramdisk.img". - Close the emulator completely, then cold boot it: Cold Boot Now in Device Manager, or
-no-snapshot-loadfrom the command line. The new ramdisk is only read on a cold boot. - Open the KernelSU Next app on the emulator. It should say Working (LKM Mode).
Under the hood it pushes the files to /data/local/tmp/ksuAVD/, pulls ksud out of the manager APK, reads the kernel's KMI and runs ksud boot-patch --ramdisk --allow-shell. Add DEBUG to keep those working files.
Root for adb shell
Nothing gets root until you grant it, adb shell included.
- In KernelSU Next, open the Superuser tab.
- From the top-right menu, turn on Show system apps.
- Set Shell (
com.android.shell) to Grant. - Run
adb shell su. You should getuid=0(root).
Going back to stock
The original ramdisk is kept as ramdisk.img.backup. To put it back:
./ksuAVD.sh restore "path/to/ramdisk.img"
ksuAVD.bat restore "path\to\ramdisk.img"Why older AVD root methods break
- 16 KB pages. From Android 15, emulator images can use 16 KB memory pages. Tools built only for 4 KB pages crash with
mprotect failed;ksudand the KernelSU Next modules handle both. - GKI. Android 12+ emulators run Google's Generic Kernel Image. KernelSU Next loads into it as a module, so there's no patched kernel binary.
Credits: HChenX (KernelSU-AVD, the base of both scripts), rifsxd and the KernelSU Next team, tiann and weishu (KernelSU), newbit (rootAVD). GPL-3.0. The author calls it a personal tool and says to expect bugs.