I have All Android SDK versions(from 1.5 to 2.3.3), and I tried many methods for getting root in Android emulator. I don't use any Android device and test everything on emulator(AVD).
I need to get root access in any one of the Android emulator to use the 'iptables' and 'busybox' functionality. And to use iptables I must have root access. Atleast 'su' command should execute in the terminal emulator.
I also installed z4root
application,
But it takes very long time and doesn't finish rooting, and gets stuck. some say that if we downgrade the system to below RC30, this way we can get root access. if this is true, then how to do this? I use both Linux and Windows OS.
Please someone tell me any method to root my emulator.
For AVD with 5.1.1 and 6.0 I used next script in windows:
Need UPDATE.zip from SuperSU. Unpacked them to any folder. Create bat file with content above. Do not forget specify necessary architecture and device:
set adb=adb -s emulator-5558
andset arch=x64
. If you run Android above or equal 5.0, changeset pie=
toset pie=.pie
. Run it. You get temporary root for current run.If you got error on remount system partition then you need start AVD from command line. See below first step for Android 7.
If you want make it persistent - update binary in SuperSU and store system.img from temp folder as replace of default system.img.
How to convert the resulting temporary root on a permanent
First - it goes to SuperSu. It offers a binary upgrade. Update in the normal way. Reboot reject.
Second - only relevant for emulators. The same AVD. The bottom line is that changes in the system image will not be saved. You need to keep them for themselves.
There are already instructions vary for different emulators.
For AVD you can try to find a temporary file system.img, save it somewhere and use when you start the emulator.
In Windows it is located in the
%LOCALAPPDATA%\Temp\AndroidEmulator
and has a name something likeTMP4980.tmp
.You copy it to a folder avd device (
%HOMEPATH%\.android\avd\%AVD_NAME%.avd\
), and renamed to thesystem.img
.Now it will be used at the start, instead of the usual. True if the image in the SDK is updated, it will have the old one.
In this case, you will need to remove this
system.img
, and repeat the operation on its creation.More detailed manual in Russian: http://4pda.ru/forum/index.php?showtopic=318487&view=findpost&p=45421931
For android 7 you need run additional steps: 1. Need run emulator manually. Go to sdk folder
sdk\tools\lib64\qt\lib
. Run from this folder emulator with options-writable-system -selinux disabled
Like this:You need restart
adbd
from root:adb -s emulator-5554 root
And remount system:
It can be doned only once per run emulator. And any another remount can break write mode. Because of this you not need run of any other commands with remount, like
mount -o remount,rw /system
.Another steps stay same - upload binary, run binary as daemon and so on.
Picture from AVD Android 7 x86 with root:
If you see error about PIE on execute
su
binary - then you upload to emulator wrong binary. You must upload binary namedsu.pie
inside archive, but on emulator it must be named assu
, notsu.pie
.I believe that the easiest way is to create an alias for the command
sh
, e.g.Tested on Android Emulator 3.0 and higher.
I just replaced and assigned attributes for su to ~/Android/Sdk/system-images/android-22/google_apis/x86/system.img and now on android 5 I always have root even for new systems, it’s enough to install SuperSu.apk
after that, SuperSu.apk sees root. But I do not update the binary file
I tried many of the above suggestions, including SuperSU and couldn't get any to work but found something much simpler that worked for my purposes. In my case, I only wanted to be able to run sqlite at the command prompt. I simply spun up an emulator with an older version of Android (Lollipop) and got root access immediately.
Try other way to solve this question.
Use Genymotion instead of the Default Android Emulator. It's rooted by default. It's much easier and more like a normal Phone. It's free for personal use.
I found this question because I want to install Xposed framework on the Default Android Emulator. That installation needs root and flash with a custom recovery (e.g. TWRP), both are difficult for the Default Android Emulator. At last I used Genymotion and all done in minutes.
Here is the list of commands you have to run while the emulator is running, I test this solution for an avd on Android 2.2 :
It assumes that the su binary is located in the working directory. You can find su and superuser here : http://forum.xda-developers.com/showthread.php?t=682828. You need to run these commands each time you launch the emulator. You can write a script that launch the emulator and root it.