Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save behnejad/18d9aa8dbe07514226d33dde00a094d3 to your computer and use it in GitHub Desktop.

Select an option

Save behnejad/18d9aa8dbe07514226d33dde00a094d3 to your computer and use it in GitHub Desktop.

Preface

Genymotion recently moved root access behind a paywall (only since Android 12.0), making it a premium feature. However, if you're using Genymotion for Android development, testing, or educational purposes, having root access can be essential. Root access allows developers to access deeper functionality, test root-only features, and explore Android's internals without restrictions.

The good news is that with a bit of work, you can still enable root on a Genymotion emulator if you have access to its disk image and platform keys. This guide walks you through the process of adding a custom system app, RootToggle, which will allow you to switch root access on and off without needing Genymotion's paid root access feature.

This Gist details the steps to compile, sign, and install RootToggle as a system app in a Genymotion emulator by directly modifying the emulator's disk image IN LINUX (use a virtual machine on Windows to do that).


Contents

  • RootToggle-signed.apk — Ready-to-use signed APK
  • RootToggle.zip — Source code (optional, for self-compilation)
  • This guide

Prerequisites

  • Linux environment (use a VM on Windows/macOS)
  • qemu-utils — for qemu-nbd (sudo apt install qemu-utils)
  • Android SDK Build Tools — only needed if compiling the APK yourself

Note

Does this work in WSL? I haven't tested it. If you try, please let me know in the comments!


1. (Optional) Compile the RootToggle App Yourself

If you prefer to compile the RootToggle app yourself, follow these steps:

  1. Get the source: Download source.zip

  2. Build the APK: Open the project in Android Studio and build the APK, or use the Gradle command line.

    ./gradlew assembleRelease
  3. Locate the Unsigned APK: After building, the unsigned APK will be in the app/build/outputs/apk/release directory.

2. Get the Platform Keys

You will need platform.pk8 and platform.x509.pem keys for the emulator from this official repo here. If for some reason this repo doesn't exist anymore, you could get it here.

git clone https://github.com/Genymobile/genymotion_platform_vendor_genymotion_security_public
cp genymotion_platform_vendor_genymotion_security_public/release-keys/platform* .

3. Sign the APK with Platform Keys

Run the following command to sign the APK:

/path/to/build-tools/<version>/apksigner sign \
  --key platform.pk8 \
  --cert platform.x509.pem \
  --out RootToggle-signed.apk \
  app/build/outputs/apk/release/app-release-unsigned.apk

The signed APK is now ready to be installed as a system app.

4. Install RootToggle as a System App

Using QEMU and qemu-nbd, we’ll add the signed APK to the Genymotion emulator’s system partition.

Warning

Make sure the Genymotion emulator is completely stopped before modifying the disk image. Editing while running can corrupt the image.

Step-by-Step Commands

  1. Load the NBD (Network Block Device) Module:

    sudo modprobe nbd
  2. Attach the QCOW2 Disk Image:

    sudo qemu-nbd --connect=/dev/nbd0 ~/.Genymobile/Genymotion/deployed/<device_name>/system.qcow2

Note

Best is to get the system.qcow2 from the deployed VMs as it is the one that is used by only one device. However, if you want to modify the system image for every new emulator you create, you can modify the system.qcow2 in the system images folder instead. The paths are:

  • Deployed VMs: ~/.Genymobile/Genymotion/deployed/<device_name>/system.qcow2
  • System images: ~/.Genymobile/Genymotion/system-images/<image_version>/<android_version>/system.qcow2

macOS/Windows users: Copy system.qcow2 to a Linux machine to modify it (or use WSL).

  1. Identify the System Partition:

    Run sudo fdisk -l /dev/nbd0 to find the correct partition. Look for a partition labeled system or the largest ext4 partition (typically 2-4 GB). It's usually /dev/nbd0p4.

  2. Mount the System Partition:

    sudo mkdir -p /mnt/android_system
    sudo mount /dev/nbd0p4 /mnt/android_system
  3. Create the App Directory:

    sudo mkdir -p /mnt/android_system/system/priv-app/RootToggle
  4. Copy the Signed APK:

    sudo cp RootToggle-signed.apk /mnt/android_system/system/priv-app/RootToggle/RootToggle.apk
  5. Set the Correct Permissions:

    sudo chmod 644 /mnt/android_system/system/priv-app/RootToggle/RootToggle.apk
  6. Unmount and Disconnect:

    sudo umount /mnt/android_system
    sudo qemu-nbd --disconnect /dev/nbd0

Tip

If mounting fails or you encounter errors, make sure to disconnect nbd first:

sudo qemu-nbd --disconnect /dev/nbd0

5. Start the Emulator

Start your Genymotion emulator as usual. The RootToggle app should now be installed as a system app with the necessary permissions to modify persist.sys.root_access.

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment