201

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.

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Preetam
  • 5,528
  • 10
  • 32
  • 39
  • 12
    Please note that android emulators already are "rooted". You do not need to do anything to get a root adb shell, as it already runs as root by default. What is discussed here is installing a hacked "su" or similar shim to allow application code to launch helper programs that run as root. – Chris Stratton Mar 07 '14 at 15:28
  • In an unhelpfully deleted answer, it has been pointed out that the emulator kernel typically lacks support for iptables anyway. – Chris Stratton Mar 07 '14 at 15:35
  • Linked http://stackoverflow.com/questions/4924391/how-to-get-root-access-on-android-2-3-emulator and http://stackoverflow.com/questions/8425352/root-access-on-android-sdk-emulator – Paul Verest Mar 12 '14 at 09:34
  • 3
    Use Genymotion https://www.genymotion.com/ It's very fast and has root by default. – klimat Dec 25 '14 at 15:39
  • You should update answer here. The simplest working solution is from JRaymond where he start with `adb root` and then `adb shell` – Damian Petla Dec 27 '16 at 13:44
  • I think you can use "Root.apk" stored on filecrop ( VISIONary in android system ) to root the emulator because, at each reboot, it root the system. Z4root can't work because it needs rebooting to make the root access working.Sorry for bad english, I'm french. – JeremLeOuf Jun 29 '12 at 07:56
  • Where can i get this ? Is there a manual for this ? – android developer Feb 08 '13 at 08:16
  • 1
    you installed the wrnong image. see here --> https://stackoverflow.com/questions/43923996/adb-root-is-not-working-on-emulator – otto Nov 18 '18 at 18:03

15 Answers15

170

If you have a virtual device with root access, this should do the job:

$ > adb shell
generic_x86:/ $
generic_x86:/ $ exit
$ > adb root
restarting adbd as root
$ > adb shell
generic_x86:/ #

If you don't, you might be interested in this answer to a different question, which explains how to create an virtual device with root access, with Google APIs (aka Google Play services), but without the Google Play app.

If you really need the Google Play app, you might be interested in other answers which instruct how to root an Android virtual device.

cubuspl42
  • 7,833
  • 4
  • 41
  • 65
JRaymond
  • 11,625
  • 5
  • 37
  • 40
  • 1
    Perfect. Tested on the latest SDK tools 25.2.5, SDK Platform Tools 25.0.2 and x86_64 API 24 emulator. In addition to above, I checked a user with "id" command: 127|generic_x86_64:/ # id uid=0(root) gid=0(root) groups=0(root),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc) context=u:r:su:s0 – yvolk Jan 22 '17 at 15:52
  • 87
    Running `adb root` results in "adbd cannot run as root in production builds". Are you using a particular emulator? Please provide more details. – orodbhen Jul 22 '17 at 01:48
  • @orodbhen well I use the x86 emulator, but otherwise nothing special... just make sure your phone isn't plugged in when you do it – JRaymond Jul 23 '17 at 21:14
  • @jRaymond Looks like the Pixel emulator works, but not the Nexus 5x. Both with Android 7.0 API 24. – orodbhen Jul 23 '17 at 22:05
  • @orodbhen that's odd - they must have released the wrong image – JRaymond Jul 24 '17 at 19:24
  • 6
    You can not use this root for any app. – Enyby Jul 27 '17 at 23:09
  • @Enyby that's true... but that's not what OP asked for - they wanted to be able to use command line utilities – JRaymond Jul 28 '17 at 23:24
  • 8
    If anyone is trying to get this to work on the new Google Play system images, adbd is set to secure in ramdisk.img. I was able to work around it by using ramdisk.img from the Google APIs image. I tested on both the 7.0 and 8.0 images. – tstaylor7 Aug 11 '17 at 21:06
  • 82
    If `adb root` gives the error `adbd cannot run as root in production builds`, see https://stackoverflow.com/a/45668555/1682419 -- You need a "Google APIs System Image" rather than a "Google Play System Image". – Jerry101 Aug 14 '17 at 06:33
  • @tstaylor7 I replaced the ramdisk.img in google-apis-playstore with the one in google-apis. And the emulator can't start up now. – passerbywhu Nov 13 '17 at 03:42
  • 1
    @passerbywhu I'm seeing the same thing with the latest Oreo images. I was able to work around it by using an older API ramdisk. For the [r05 Playstore image](https://dl.google.com/android/repository/sys-img/google_apis_playstore/x86-26_r05.zip) (currently latest), I used the ramdisk from the [r05 API image](https://dl.google.com/android/repository/sys-img/google_apis/x86-26_r05.zip) (r07 is currently the latest). – tstaylor7 Nov 14 '17 at 05:18
  • 12
    @JRaymond I typed in adb root but nothing printed out after that –  Jun 08 '18 at 06:11
  • @guest176969 what version emulator? – JRaymond Jun 10 '18 at 19:42
  • 2
    adb shell and exit are unnecessary. – Chandler Oct 01 '18 at 21:33
  • 2
    @Chandler They are demonstrative of the state of the system before I run the command, in order to give a more complete answer, under the assumption that the reader knows what a root shell vs a regular shell look like – JRaymond Oct 01 '18 at 23:11
  • 1
    Can not be used for shells that use `su`. – MainActivity Feb 12 '19 at 10:14
  • This seems to work, thanks -- however, only after running `su` after logging in to the shell (i.e. with `adb shell`). Namely, the initial log-in let's you in with the same user, but `adb root` allows for running `su` on the device. – d4vidi Dec 04 '19 at 12:19
97

How to root android emulator (tested on Android 7.1.1/ Nougat)

Requirements:

Instructions

  1. Install the SuperSu.apk
  • Install the SuperSu app firstly, just do drag and drop (if running latest emulator version or sideload through adb i.e adb -e install supersu.apk)

  • After installing it, when you run it shows a screen as shown below indicating “There is no SU binary installed..”. This error just confirms the device is not yet rooted.

enter image description here


  1. Make emulator’ system partition writable
  • As it suggests, we need to give the emulator permission to write system files.

  • Type the following code to accomplish this: emulator -avd {emulator_name} -writable-system

If you have more than one AVD, you can get a list of avds by using the command: emulator -list-avds

Note: Navigate to the tools folder where Android SDK is installed and open command prompt there by pressing shift and right clicking.


  1. Pushing su binary in system directory
  • Extract the Recovery flashable.zip (containing the su binaries of different architectures)

Important! Only use the su binary that matches your avd architecture e.g x86, arm etc.., and note the path where you extracted these binaries.

  • Make sure you are running adb as root and also you need to remount. Just enter these codes

adb root

adb remount

Now its time to push the su binary:

This is the code I successfully used: adb -e push C:\Users\User1\Desktop\rootemu\x86\su.pie /system/bin/su

(nevermind about my specific location of su binary, any location is okay as long there is no white space)

note: To figure out bin or xbin do in console before: > adb shell, > ls /system/xbin/su

If this fails try this pushing to this directory instead /system/xbin/su. Also for emulators running android 5.1 and below use the su and not su.pie


  1. Change permissions of the su binary
  • Next let’s do a bit of modification of the permissions of su binary. We have to do this in emulator device through adb:
adb -e shell
su root
cd /system/bin
chmod 06755 su

Important!! Take note of su binary path (mine is /system/bin)


  1. Setting the install directive on su binary and set a daemon

Type the codes:

su --install

and for setting up daemon:

su --daemon&

Important!! Take note of spacing


  1. Setting SELinux to Permissive(i.e turning off SE Linux)
  • Finally turn off selinux through this code:

setenforce 0


Open SuperSU app and it may ask to update binaries, you can use Normal method.

Note: If you're experiencing bootloops, rather don't update the binaries, just use it as it is.


That’s pretty much it!!

Open any application requiring SU permissions just to double check and indeed SuperSU ask if you wish to grant it su permissions.

enter image description here

To have the root persist update su binary (using Normal method), then copy system.img from temp directory (Users\AppData\Local\Temp\Android Emulator the file is usually randomly named e.g 1359g.tmp with a large size) and replace default system.img.

Update:

I have noted is is easier to obtain a temporary system image in Linux, than Windows. You can try using snapshot image.

##Update 4 August 2018

With the emergence of emulator 27.3.x it now makes preserving root much easier through snapshot feature (if copying the system.img method isn't working):

Ideally it is more like hibernarig the virtual device with config intact, hence everything is preserved.

Snapshots

You can now save multiple AVD snapshots for a given device configuration and choose which of the saved snapshots to load when you start the emulator. Starting a virtual device by loading a snapshot is much like waking a physical from a sleep state, as opposed to booting it from a powered-off state.

This implies the only requirement to start the emulator is adding the -writable-system parameter to the normal emulator -avd [avdname] command to start the emulator. (Running the emulator just with emulator -avd [avdname] doesn't launch the rooted version/copy or may lead to some error)

Tested on API level 22

Also for bootloop issues see the other post: Android Emulator: How to avoid boot loop after rooting? and updates thereof.

Remarks

Most content in reference was for older android versions and hence the reason for different commands and paths which I modified.

Acknowledgements;

Miloš Černilovský
  • 3,846
  • 1
  • 28
  • 30
xavier_fakerat
  • 1,671
  • 14
  • 22
  • 1
    note: To figure out bin or xbin do in console before: > adb shell, > ls /system/xbin/su – djdance Aug 11 '17 at 14:16
  • 1
    @xavier_fakerat yes, I stopped updated the binaries. The problem is, after each reboot I have to remount the machine and run the `su --install && su --daemon&` on the emulator, followed by `setenforce 0` to get root. Do you know any permanent fix for root at reboot? – Cristian Holdunu Aug 31 '17 at 13:31
  • unable to type adb root, cmd prompt stuck after writable-system, why :(( – Beeing Jk May 16 '18 at 11:19
  • @BeeingJk Please check if adb server version is matching with the client see: https://stackoverflow.com/q/5092542 – xavier_fakerat May 25 '18 at 11:26
  • @АксеновВладимир Looks like things changed a bit, avd manager has been phased out in latest android sdk tools, so you need to use console, unfortunately – xavier_fakerat May 25 '18 at 11:27
  • @ImanMarashi make sure you mounting system with `rw` permissions, i.e adb root and the remount make sure the console displays `#` instead of `$`.. – xavier_fakerat May 25 '18 at 11:31
  • 1
    Nice! This method also works for real devices that you can access root via adb. – Mygod Aug 19 '18 at 16:00
  • 1
    You answered me to, why android emulator closes unexpectedly after rooting the image when not using -writable-system. It's because the snapshots. – Rodrigo García Oct 08 '18 at 21:10
  • When I try to push the su file, I get the error `adb push C:\Users\_\Downloads\su\x86\su /system/xbin/su adb: error: failed to copy 'C:\Users\_\Downloads\su\x86\su' to '/system/xbin/su': remote No space left on device` What should I do? – Ahmad Sattout Nov 08 '18 at 07:45
  • 1
    @xavier_fakerat Hi, when doing `setenforce 0` I see the process `su --daemon&` as done, so disabling SELinux is killing su daemon on my device. Then when I go in SuperSu I see "root undetected". The same happen if I let SELinux enforced. I also tried both bin and xbin. Another user has the same problem https://android.stackexchange.com/questions/175669/manually-rooting-what-else-is-needed – noraj Dec 03 '18 at 15:55
  • PS : I'm using android 9.0. I used root checker (com.joeykrim.rootcheck) with advanced feeback, it is telling me that supper su app is installed (stage 1), superuser binary files are installed (stage 2) but I get an error at Root User Account (stage 3): Error: stdrr: null, stdout: null, exit_value: 159. I'm using supersu 2.82 – noraj Dec 03 '18 at 16:17
  • 2
    I'm using Pixel 2 XL: People seem to have the same problem with the Pixel XL: https://forum.xda-developers.com/pixel-xl/how-to/guide-pixel-xl-android-9-0-pie-unlock-t3825866/page2 – noraj Dec 03 '18 at 16:20
  • I tested exactly the same steps on a Pixel 2 XL but android 7.1.1 (api 25) instead of android 9.0 (api 28) and it worked. So something changed in between. – noraj Dec 03 '18 at 17:23
  • Worked on API 23 x86-64 emulator while other answers give errors. – MainActivity Feb 12 '19 at 10:48
  • 1
    Thx very mutch! <3 (Android 7.1 x86) – Doofy Feb 23 '19 at 05:02
  • 4
    A step was missing here - after step 1, you need to close the emulator. Because the command in step 2 is actually starting the emulator... If you do not close it, you will get an error saying running multiple emulator is an experimental feature – Sira Lam Dec 04 '19 at 07:52
  • 2
    1st link is dead – pookie Jan 31 '20 at 14:19
  • 1
    Remount is broken for API 29, use API 28 instead – Andras Szell Mar 18 '20 at 12:56
  • "chmod 06755 su" should be "chmod 0755 su" – swizes Apr 09 '20 at 19:59
  • After rooting and rebooting, it went into a bootloop and I had to wipe the VM, which unrooted it again. Repeating logcat error: `type=1400 audit(0.0:12): avc: denied { execute_no_trans } for path="/system/xbin/daemonsu" dev="vda" ino=1628 scontext=u:r:init:s0 tcontext=u:object_r:system_file:s0 tclass=file permissive=0` – Fusseldieb Jul 10 '20 at 18:31
  • emulator -avd Pixel_4_API_30 -writable-system PANIC: Missing emulator engine program for 'x86' CPU ...fixed, I had to run from this folder C:\Users\'User'\AppData\Local\Android\Sdk\emulator – rulet Mar 03 '21 at 10:50
  • 3
    adb root adbd cannot run as root in production builds – rulet Mar 04 '21 at 12:37
  • If `adb root` works then why bother installing `su`? – Ken Sharp Mar 05 '21 at 00:04
  • Step 5 doesn't work? `su: invalid uid/gid '--install'` – spacer GIF May 05 '21 at 15:15
33

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 :

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system  
adb push su /system/xbin/su  
adb shell chmod 06755 /system  
adb shell chmod 06755 /system/xbin/su

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.

a.b.d
  • 2,190
  • 3
  • 26
  • 26
  • 17
    Please include the relevant parts of your blog post here. SO is a place for answers, not links. – cHao Jun 01 '11 at 23:13
  • 4
    No such file or directory 'SU' – Mahendran Feb 14 '12 at 13:27
  • 4
    This doesn't work on emulator 2.2, 2.3 or 2.3.3 I get only errors for adb push: out of memory, dir is not empty, etc. – Pointer Null Feb 28 '12 at 09:57
  • 2
    @mice: As the error says you can't push the binary because there is not enough space on the virtual device. When launching the emulator you can add the `-partition-size` option to specify the partition size. Try launching your emulator with `tools/emulator -avd MyAndroidVirtualDeviceName -partition-size 256` – a.b.d Dec 03 '12 at 05:40
  • @a.b.d Could you be so kind as to tell me how to do the adb commands at the running instance? I am new to this, but I don't understand where to type in all the "adb" stuff, (In Terminal on Mac)... Don't the commands above "adb shell..." need to be entered on the device end not mac end? – dkugappi Feb 14 '13 at 02:18
  • I mean the "virtual" device end. – dkugappi Feb 14 '13 at 02:28
  • OK so I am getting warmer - the problem I am having is that if I run the emulator from the Terminal, ./adb devices doesn't list it. If I runt it from Eclipse it works but then gives the "Out of memory" message. Catch 22. Any ideas? – dkugappi Feb 14 '13 at 03:39
  • 1
    The answer here is 100% compatible with Windows, by the way: http://stackoverflow.com/questions/9921874/rooting-ics-emulator-pushing-su-fails-with-out-of-memory Be in the command prompt, in C:\adt\sdk\tools, or wherever your tools directory is. If you're in Explorer, you can shift+right click for an "open command prompt here" option. –  Oct 23 '13 at 16:47
  • am getting an error of cannot stat 'su' no such file (or) directory. How to resolve this? – AndroidOptimist Mar 03 '14 at 11:01
  • I have just found a video in Youtube that seems to be using this trick. Maybe it's helpful? https://www.youtube.com/watch?v=hx399KPutUY – Savir Mar 11 '14 at 21:08
  • 2
    On newer emulators the remount command may not work, you may replace: `adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system` with: `adb root` `adb remount` – Kamran Ahmed Apr 18 '16 at 13:15
  • 1
    Not working on API 23 emulator, `can't create su: Read-only file system` despite `adb remount` succedes. `adb shell mount` exits with `permission denied`. – MainActivity Feb 12 '19 at 09:07
  • 1
    Also not working on API 16 emulator. `adb remount` fails with `Permission denied`. – GDorn Jun 30 '19 at 06:08
20

For AVD with 5.1.1 and 6.0 I used next script in windows:

set adb=adb -s emulator-5558
set arch=x64
set pie=
adb start-server
%adb% root
%adb% remount
rem %adb% shell mount -o remount,rw /system
%adb% shell setenforce 0
%adb% install common/Superuser.apk
%adb% push %arch%/su%pie% /system/bin/su
%adb% shell chmod 0755 /system/bin/su
%adb% push %arch%/su%pie% /system/xbin/su
%adb% shell chmod 0755 /system/xbin/su
%adb% shell su --install
%adb% shell "su --daemon&"
rem %adb% shell mount -o remount,ro /system

exit /b

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 and set arch=x64. If you run Android above or equal 5.0, change set pie= to set 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 like TMP4980.tmp.

You copy it to a folder avd device (%HOMEPATH%\.android\avd\%AVD_NAME%.avd\), and renamed to the system.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:

F:\android\sdk\tools\lib64\qt\lib>F:\android\sdk\tools\emulator.exe -avd 7.0_x86 -verbose -writable-system -selinux disabled
  1. You need restart adbd from root:

    adb -s emulator-5554 root

And remount system:

adb -s emulator-5554 remount

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: 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 named su.pie inside archive, but on emulator it must be named as su, not su.pie.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Enyby
  • 4,162
  • 2
  • 33
  • 42
  • Can you tell me the steps to make the root persistent? – Satya Dec 23 '15 at 04:21
  • `update binary in SuperSU and store system.img from temp folder as replace of default system.img.` – Enyby Dec 23 '15 at 14:40
  • I used these steps to get the system.img from temp 1) cp /tmp/android/emulator-X8F7Hr ~/Desktop/system.img 2) copied this system.img from temp in the system-images of Android SDK But when I restart the emulator then the emulator is not in rooted state... Please guide me the correct path – Satya Dec 24 '15 at 08:21
  • better copy to avd directory. but first you must update binary in SuperSu in normal mode. – Enyby Dec 24 '15 at 14:11
  • I have updated binary in normal mode and copied in AVD directory then also root is not persisting – Satya Dec 28 '15 at 05:42
  • I do not know. I'm on windows it works this way. Maybe in linux something different. I've not prompt. – Enyby Dec 28 '15 at 07:20
  • The steps you mentioned is working perfectly for Lollipop but not for Android 6.0 – Satya Dec 28 '15 at 12:18
  • Yes. You need fully disable SELinux or get proper settings for it. Settings stored in `/sepolicy` file. Settings for full disable located in `/default.prop`. It stored in rootfs and may be hardcoded in kernel. For me enough temp root. If you want you can search how set `ro.secure=0` in `default.prop`. May be it need recompile kernel. – Enyby Dec 29 '15 at 00:31
  • @Satya Yes. But no luck. I can not remount system for rw from root - Permission denied. Without it can not get root. I think need update for SuperSU. And You can not get root on preview release. Wait for full release. – Enyby Apr 09 '16 at 19:33
  • I am able to root the android N emulator but when I soft boot the emulator, its going to boot loop and never showing the Home screen :( – Satya Apr 20 '16 at 09:52
  • @Enyby in avd directory, edit hardware-qemu.ini and rename disk.systemPartition.initPath to disk.systemPartition.path. more info here https://android.googlesource.com/platform/external/qemu.git/+/aa8236dc1b1ea300ab18716db5b8fab42aca3ca7/android/avd/hardware-properties.ini#317 – Henri Gourvest Jul 25 '16 at 02:29
  • @HenriGourvest I tried it before. Before it not worked. Because AVD is very modded QEMU. May be now it work - not test. – Enyby Jul 25 '16 at 02:58
  • hrm. I tried to root my current Android 6 in an emulator, but it doesn't seem to work. I placed the files in the system.img and called su --install, but SuperSU still says that it doesn't find "su". – Frederick Nord Nov 21 '16 at 13:29
13

I believe that the easiest way is to create an alias for the command sh, e.g.

adb shell
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
cd /system/bin
cat sh > su && chmod 4775 su

Tested on Android Emulator 3.0 and higher.

newbie
  • 1,230
  • 1
  • 12
  • 21
9
  1. A virtual device without "Play Store" should be used. Note: You can either create one new or edit the settings of the existing one if you have some databases already inside the emulated device.

  2. Once avd is created and is running Open terminal anywhere > in android studio or from start menu

  3. Run adb root

Now you can use adb shell to open device shell window.

If your physical device with developer options is connected you will get message like "adb.exe: more than one device/emulator" in this case you can use command 'adb -e shell'

Other useful note for beginners in adb shell:

Run 'ls' to see all the files. cd to change directory. some letters of the directory name+ TAB to auto complete the name. '..' to go back.

metvsk
  • 189
  • 2
  • 4
6

I know this question is pretty old. But we can able to get root in Emulator with the help of Magisk by following https://github.com/shakalaca/MagiskOnEmulator

Basically, it patch initrd.img(if present) and ramdisk.img for working with Magisk.

HemanthJabalpuri
  • 344
  • 4
  • 11
4

Here my pack with all you need. Or you can use this script:

echo on
set device=emulator-5554
set avd_name=
set adb=d:\Poprygun\DevTools\Android\Android-sdk\platform-tools\adb -s %device%
set emulator=d:\Poprygun\DevTools\Android\Android-sdk\emulator\emulator
set arch=x86
set pie=

echo Close all ANDROID emulators and press any key
pause
start %emulator% -avd Nexus_One_API_25 -verbose -writable-system
echo Wait until ANDROID emulator loading and press any key
pause

%adb% start-server
%adb% root
%adb% remount
%adb% shell setenforce 0
%adb% install D:\SuperSU\SuperSU.apk
%adb% push D:\SuperSU\su\%arch%\su.pie /system/bin/su
%adb% shell chmod 0755 /system/bin/su
%adb% push D:\SuperSU\su\%arch%\su.pie /system/xbin/su
%adb% shell chmod 0755 /system/xbin/su
%adb% shell su --install
%adb% shell "su --daemon&"
pause
exit /b
4

https://github.com/newbit1/rootAVD save my life .

It root by Magisk

The script simple enough for user enter image description here

wyx
  • 3,334
  • 6
  • 24
  • 44
3

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

Android 6 is necessary only
adb root
adb shell
>/system/xbin/su --daemon &
>setenfoce 0

after that, SuperSu.apk sees root. But I do not update the binary file

xWeb
  • 31
  • 3
1

I used part of the method from the solutions above; however, they did not work completely. On the latest version of Andy, this worked for me:

On Andy (Root Shell) [To get, right click the HandyAndy icon and select Term Shell]

Inside the shell, run these commands:

mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
cd /system/bin
cat sh > su && chmod 4775 su

Then, install SuperSU and install SU binary. This will replace the SU binary we just created. (Optional) Remove SuperSU and install Superuser by CWM. Install the su binary again. Now, root works!

obc7787
  • 56
  • 4
1

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.

Alan Todtenkopf
  • 452
  • 4
  • 6
1

Use android image without PlayServices then you'll be able to run add root and access whatever you want.

gordinmitya
  • 967
  • 10
  • 10
0

I found that default API 23 x86_64 emulator is rooted by default.

Vladimir Berezkin
  • 3,580
  • 4
  • 27
  • 33
  • 3
    From what I know, just because you have a # when you type "adb root", doesn't mean that apps can take advantages of root privileges. Any trial to write anywhere in /system resulted in a RO error, even trying to remount it as RW. – Fusseldieb Jul 10 '20 at 18:34
-1

Now i will let know the simplest way to root your emulator in few steps using 1 command.

  1. Create or configure emulator.
  2. Check by running your application that your emulator is working or not.
  3. Open cmd and give the path of your sdk platform-tools like as below

C:\Users\XYZ>cd C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools

if you are not sure that where is your platform tools then goto android studio and open SDK Manager(Click the icon of sdk manager) there you will get the path of your sdk like this ==>C:\Users\XYZ\AppData\Local\Android\Sdk and add platform tools at the end like as below

C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools

Now follow step 3 i.e Open cmd and give the path of your sdk platform-tools like as below

C:\Users\XYZ>cd C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools

Step 4: C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools>adb root

Step 5: C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools>adb shell

Now you will get the success message as below:

C:\Users\XYZ\AppData\Local\Android\Sdk\platform-tools>adb root adbd is already running as root

Step 6 : XYZ generic # cd data/data//databases/ sqlite3 .tables .schema

Hope it will help. Its worked for me.