[AndroidStudio] How to Root Android Studio Emulator (AVD)


* Change red-colored names.

1. Create a new AVD. (named Nexus6 here)









2. Check the directory of Android SDK ($SDK_PATH) and start emulator with args as following.

$ SDK_PATH/emulator/emulator -avd Nexus6 -writable-system -selinux permissive -qemu -enable-kvm

   In my case, "-qemu -enable-kvm" didn't work on MacOS, so I skipped those args.

3. If the device is booted, restart adbd as root and remount system.

$ adb root
$ adb remount
 
   If adb command doesn't exist, make sure to add PATH.
   Mine was located in ~/Library/Android/sdk/platform-tools.

4. Download and install Superuser.apk

$ git clone https://github.com/0xFireball/root_avd.git
$ cd root_avd
$ adb install SuperSU/common/Superuser.apk

5. Pick the corresponding architecture and save it as variable $ARCH.
    Then push su, update permissions, and set SELinux peprmissive.


$ ARCH=x86
$ adb push SuperSU/$ARCH/su/system/xbin/su
$ adb shell chmod 0755 /system/xbin/su
$ adb shell setenforce 0

6. Install SuperSU's su to system and run as daemon.
$ adb shell su --install
$ adb shell su --daemon&

7. Open SuperSU app on the device and update su binary. Use normal installation.



8. You can ignore the message "Installation will fail".


TIP: Superuser may not always persist after reboot, to fix:
  1. From a root shell, start su --daemon&
  2. Root should now work.
  3. Optional: Look for the temporary emulator system image; you can back this up and use it as a patched system.



Reference: https://github.com/0xFireball/root_avd

Comments