rootAVD

newbit @ xda-developers

A Script to...

  • root your Android Studio Virtual Device (AVD), with Magisk (Stable or Canary)
  • patch its fstab
  • download and install the USB HOST Permissions Module for Magisk
  • install custom build Kernel and its Modules
  • download and install AOSP prebuilt Kernel and its Modules

...within seconds.

Install Magisk

Preconditions

  • the AVD is running
  • a working Internet connection for the Menu
  • a command prompt / terminal is opened
  • adb shell will connect to the running AVD

How To Use it

  • run rootAVD with a path to an AVDs ramdisk.img file
  • ramdisk.img gets a backup and will be replaced when done patching

How To Use it under Android S with Magisk v22.x

  • rootAVD needs to run twice
  • 1st - to patch the ramdisk.img
  • 2nd - after Shut-Down & Reboot the AVD:
    • Option 1 - re-run same script command
    • Option 2 - run script with EnvFixTask Argument
      • The "Additional Setup Required" will not be triggered in Android S by Magisk App in AVD,
      • this must be done manually on the 2nd run
      • Grant Shell Su Permissions will pop up a few times
      • rootAVD will reboot the AVD automatically
      • check Magisk App !!

Download / Install / Update a custom (pre)build Kernel and its Modules

Preconditions

  • Install Magisk Preconditions
  • build a kernel (bzImage) and its modules (initramfs.img)
  • both files are placed inside the rootAVD directory
  • ramdisk.img must be untouched (stock)

How To Use it

  • run rootAVD with the additional InstallKernelModules | InstallPrebuiltKernelModule parameter
  • the modules inside ramdisk.img will be replaced by the modules inside initramfs.img
  • kernel-ranchu gets a backup and will be placed with bzImage when done patching
  • bzImage and initramfs.img will be deleted after installation

Notes

  • Prebuilt Kernel and Modules will be pulled from AOSP

Restore Backups of Ramdisk and Kernel

Preconditions

  • none

How To Use it

  • run rootAVD with the additional restore parameter

XDA [GUIDE] How to [Build|Mod|Update] a custom AVD Kernel and its Modules

rootAVD command line parameters

Linux

./rootAVD.sh ~/Android/Sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img
./rootAVD.sh EnvFixTask
./rootAVD.sh ~/Android/Sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img restore
./rootAVD.sh ~/Android/Sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img InstallKernelModules
./rootAVD.sh ~/Android/Sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img InstallPrebuiltKernelModule

MacOS

export PATH=$PATH:~/Library/Android/sdk/platform-tools
./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img
./rootAVD.sh EnvFixTask
./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img restore
./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img InstallKernelModules
./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img InstallPrebuiltKernelModule

Windows

set PATH=%LOCALAPPDATA%\Android\Sdk\platform-tools;%PATH%
rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_playstore\x86_64\ramdisk.img

Notes

  • Android 12 (S) rev.2 needs Magisk v22.1+ or Canary
  • With the new Menu, you can choose between the newest Magisk, Canary and Stable, Version.
  • Once choosen, the script will make that Version to your local one.

Options

  • Install all APKs placed in the Apps folder
  • If you set PATCHFSTAB=true
    • fstab.ranchu will get patched to automount Block Devices like /dev/block/sda1
    • !! a custom build Kernel is needed !!
  • If you set GetUSBHPmodZ=true
    • The USB HOST Permissions Module Zip will be downloaded into /sdcard/Download

2 Ways to boot the AVD into Safe Mode

  • 1st Way - If the AVD still boots normal:
    • Tap and Hold the Power Button until the 3 Options appear
    • Tap and Hold the Power Off Button until Reboot to safe mode appears
  • 2nd Way - If the AVD stuck while booting (black screen):
    • Tap and Hold the Volume Down Button
    • The Time Window is between the Launching Emulator Bar is approx half way until the Google Boot Screen appears
  • Confirmation
    • On the Bottom Left Corner reads: Safe mode

Magisk v22.1+ Successfully tested with Stock Kernel on

Change Logs

[Apr. 2021]

  • [rootAVD.sh] - Add a Menu to choose the prebuilt Kernel and Modules Version to install
  • [General] - Added "InstallPrebuiltKernelModule" download/update/install prebuilt kernel and modules
  • [General] - Added 2 Ways to boot the AVD into Safe Mode
  • [rootAVD.sh] - Added Android S rev 3 support
  • [General] - Added "InstallKernelModules" update/install custom build kernel and modules
  • [rootAVD.sh] - Added update_lib_modules function
  • [General] - Added "restore" to put back your backup files
  • [General] - Updated local Magisk App v22.1
  • [rootAVD.sh] - Added Option to Download the USB HOST Permissions Module
Archive

Change Logs

[Mar. 2021]

  • [General] - Add a Download Manager Function for bad TLS record using wget
  • [rootAVD.bat] - Adjustments to run with the updated rootAVD.sh
  • [General] - Add a Menu to choose the Magisk Version to install
  • [rootAVD.sh] - Added EnvFixTask Argument to fix Requires Additional Setup in Android S
  • [General] - Changed to BusyBox (D)ASH Standalone
  • [General] - Re-Structured Script
  • [rootAVD.sh] - Added "Additional Setup Required" manually for Android S
  • [rootAVD.sh] - Updated shakalaca's Ramdisk Repack Routine
  • [rootAVD.sh] - Added Compression Detection for LZ4 and GZ
  • [General] - Fixed some bugs and typos
  • [General] - Updated to Magisk App v22.0

Magisk v21.4 Successfully tested with Stock Kernel on

Credits

S
Description
Script to root AVDs running with QEMU Emulator from Android Studio
Readme GPL-3.0 72 MiB
Languages
Shell 81.4%
Batchfile 18.6%