KernelSU Next AVD

ymuuuu

v1.0.2
Version
36.72 KB
Size
Oct 19, 2026
Updated

Module Info

  • Contributors ymuuuu
  • Source Code View Repository
  • Tags
    #KernelSU Next #AVD #Android Emulator #Android Studio #LKM #GKI #ymuuuu
  • Requirement
    Non-Root

About this module

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

EmulatorResult
Android 16Works, the only version confirmed end to end
Android 15Fails, with errors from KernelSU Next itself
Everything elseUntested

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.12 or newer, on x86_64 or arm64-v8a.
  • adb in your PATH, or in the default SDK folder (%LOCALAPPDATA%\Android\Sdk on Windows, ~/Android/Sdk elsewhere).
  • The emulator already running. Check with adb devices.

Rooting the emulator

  1. 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.
  2. 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".
  3. Close the emulator completely, then cold boot it: Cold Boot Now in Device Manager, or -no-snapshot-load from the command line. The new ramdisk is only read on a cold boot.
  4. 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.

  1. In KernelSU Next, open the Superuser tab.
  2. From the top-right menu, turn on Show system apps.
  3. Set Shell (com.android.shell) to Grant.
  4. Run adb shell su. You should get uid=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; ksud and 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.