Installing Magisk and LSPosed on emulated Android

After attempting many different ways of getting Magisk to run on Android emulators (including Waydroid and the like), the only way that worked is using the official emulator from Google, along with the instructions from the following Gist:

tothi/magisk_ramdisk_patch_avd.sh

Notes

Here are the command-line flags I use to start the emulator:

emulator @android12-play \
    -partition-size 16384 \
    -memory 8192 \
    -no-audio \
    -feature -Vulkan \
    -gpu host \
    -ramdisk ~/.android/avd/android12-play.avd/ramdisk-patched.img

Note: I used to specify the number of emulated CPU cores like so: -cores 8. But for whatever reason, this breaks snapshot functionality.

Userspace installation

After getting the emulated device up and running with a patched ramdisk.img, finish setting up Magisk as follows:

  1. Install Magisk by sideloading the APK: adb install Magisk-v27.0.apk. See the GitHub releases page.

  2. Open up Magisk. (Note that the app may not show up in the apps list until Android initial setup has completed.) Follow the prompt requesting for a reboot to perform “additional setup”.

  3. Copy the LSPosed zygisk ZIP over to the device: adb push LSPosed-v1.9.2-7024-zygisk-release.zip /sdcard/Download/. LSPosed is no longer under development, so download the last available release from GitHub.

  4. Open up Magisk and select the Modules tab. Choose “Install from storage” and select the LSPosed ZIP file. After installing, you will be prompted to reboot again.

  5. After rebooting, you should have a silent notification “LSPosed loaded”. Tap to open the LSPosed interface, and choose whether you want to add an app shortcut.

  6. Now you can search for modules in the “Repository” tab and install them!