Prerequisites
Ensure you have ADB (Android Debug Bridge) installed and accessible from your command line. The Android Studio Emulator should also be properly configured and executable either through command line or via its absolute path.
Creating the Emulator
Begin by launching Android Studio and creating a new Android Virtual Device (AVD). Pay special attention to the service type selection during AVD creation, which may include options like Google Play Store, Google APIs, or Android Open Source. The appropriate selection depends on your specific testing requirements.
Launching the Emulator
Start the emulator from your command line using the following command:
emulator -avd <your_avd_name> -writable-system -no-snapshot-load
This command ensures that all system modifications will be applied and persist across sessions.
Cloning the RootAVD Repository
Download the necessary tools by cloning the RootAVD repository:
git clone https://gitlab.com/newbit/rootAVD.git/
cd rootAVD
Identifying Available AVD Images
Discover all available AVD images using the following command:
./rootAVD.sh ListAllAVDs
This will display a list of compatible system images with their paths, similar to:
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img FAKEBOOTIMG
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img DEBUG PATCHFSTAB GetUSBHPmodZ
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img restore
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img InstallKernelModules
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img InstallPrebuiltKernelModules
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img InstallPrebuiltKernelModules GetUSBHPmodZ PATCHFSTAB DEBUG
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img AddRCscripts
Applying Root Patches
Based on your AVD's service type (Google Play Store, Google APIs, or Android Open Source) and API version, select the appropriate root patch. For instance, if you're using Google APIs with Android 35, execute:
./rootAVD.sh system-images/android-35/google_apis/arm64-v8a/ramdisk.img
Rebooting the Emulator
After patching is complete, shut down the emulator and restart it with the same parameters used initially:
emulator -avd <your_avd_name> -writable-system -no-snapshot-load
Once the emulator has restarted, open the Magisk application, select the installation option, and confirm the installation. After completion, reboot the system again.
Verifying Root Access
Confirm root privileges through ADB by executing these commands:
adb shell
su
When prompted, authorize the root access request in Magisk to complete the process.