How to root Android emulator?

I have all versions of the Android SDK (from 1.5 to 2.3.3), and I have tried many ways to get root in the Android emulator. I do not use an Android device and do not test everything on an emulator (AVD).

I need to get root access in any of the Android emulators to use the iptables and busybox functions. And to use iptables, I must have root access. The Atleast 'su' command must be executed in a terminal emulator.

I also installed the z4root app,

But it takes a lot of time and does not finish rooting and gets stuck. some say that if we downgrade the system to below RC30, this way we can gain root access. if so, how to do it? I am using Linux and Windows OS.

Please tell me some method to run my emulator.

+91
android emulator root
Feb 23 '11 at 18:22
source share
10 answers

All these answers are unnecessarily complicated :)

 $ > adb shell generic_x86:/ $ generic_x86:/ $ exit $ > adb root restarting adbd as root $ > adb shell generic_x86:/ # 
+82
Oct 17 '16 at 23:39
source share

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

Requirements :

instructions

  1. Install SuperSu.apk

    • First install the SuperSu application, just drag it (when starting the latest version of the emulator or adb -e install supersu.apk via adb, i.e. adb -e install supersu.apk )

    • After installing it, at startup, the screen shown below is displayed: "There is no binary installed ...". This error simply confirms that the device has not yet been deployed.

enter image description here




  1. Record emulator system partitions

    • As follows from this, we need to provide emulator permission to write system files.

    • Enter the following code for this: emulator.exe -avd {emulator_name} -writable-system

Note. Go to the tool folder in which the Android SDK is installed and open the command line by pressing shift and right-clicking.




  1. Clicking subin in the system catalog

    • Extract Recovery flashable.zip (containing su binaries of different architectures)

Important! Use only the su binary that matches your avd architecture like x86, arm, etc., and pay attention to the path where you extracted these binaries.

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

adb root

adb remount

Now it's time to press subin:

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

(it doesn’t matter about my specific location of the subbinal, any place is in order, since there are no spaces left)

note: For xbin what bin or xbin do in the console before:> adb shell ,> ls/system/xbin/su

If this fails, try clicking on this directory instead of /system/xbin/su . Also for emulators running android 5.1 and below, use su rather than su.pie




  1. Change permissions of a binary

    • Next, let's change the su permissions of the binary files a bit. We must do this in the emulator via adb:

    adb -e shell su root cd/system/bin chmod 06755 su

Important!! Pay attention to the su binary path (my is / system / bin)




  1. Install install directive on su binary and install daemon

Enter codes:

su --install

and to install the daemon:

su --daemon&

Important!! Pay attention to the distance




  1. Installing SELinux in Permissive (i.e. disabling SE Linux)

    • Finally disable selinux through this code:

setenforce 0




  1. Open the SuperSU application and ask to update the binaries, you can use the Normal method.

Note. If you are experiencing bootloops, rather than updating the binaries, just use them as is.




This is pretty much it!

Open any application that requires SU permission only for double verification, and indeed, SuperSU will ask if you want to grant it su permissions.

enter image description here

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

Update :

I noticed that it is easier to get a temporary system image on Linux than Windows. You can try using a snapshot.

August 4, 2018 Patch

With the advent of the 27.3.x emulator, 27.3.x now greatly simplifies root preservation thanks to the snapshot function (if copying the system.img method does not work):

Ideally, this is more like a hibernarig virtual device with an intact configuration, so everything is saved.

snapshots

Now you can save several AVD snapshots for this device configuration and choose which of the saved snapshots to load when the emulator starts. Starting a virtual device by loading a snapshot is very similar to waking a physical one from a standby state, as opposed to loading it from a power off state.

This means that the only requirement to run the emulator is to add the -writable-system parameter to the regular emulator -avd [avdname] to run the emulator. (Starting the emulator only with emulator -avd [avdname] does not start emulator -avd [avdname] version / copy or may cause some error)

Tested at API Level 22

Also for problems with bootloop, see Another post: Android Emulator: How to avoid a boot cycle after rooting? and their updates.

remarks

Most of the links were about older versions of Android and, therefore, the reason for the different commands and paths that I modified.

Acknowledgment;

+50
Jun 10 '17 at 12:40
source share

Here is a list of commands that you should run while the emulator is running, I am testing this solution for 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 is assumed that the su-binary file is in the working directory. Here you can find su and superuser: http://forum.xda-developers.com/showthread.php?t=682828 . You need to run these commands every time you start the emulator. You can write a script that will run the emulator and run it.

+32
May 21 '11 at 21:02
source share

For AVD with 5.1.1 and 6.0, I used the following script in the 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. Unzip them to any folder. Create a bat file with the contents above. Do not forget to specify the necessary architecture and device: set adb=adb -s emulator-5558 and set arch=x64 . If you run Android above or equal to 5.0, change set pie= to set pie=.pie . Run it. You get a temporary root for the current run.

If you encounter an error while rebooting the system partition, you need to start AVD from the command line. Below is the first step for Android 7.

If you want to make it permanent, update the binary in SuperSU and save system.img from the temp folder as the default replacement for system.img.

How to convert the resulting temporary root to permanent

Firstly, he goes to SuperSu. It offers a binary update. Update as usual. Reload reject.

The second is relevant only for emulators. The same AVD. The bottom line is that changes to the system image will not be saved. You must keep them for yourself.

There are already instructions for different emulators.

For AVD, you can try to find a temporary system.img file, save it somewhere and use it when the emulator starts.

On Windows, it is located in %LOCALAPPDATA%\Temp\AndroidEmulator and has a type name TMP4980.tmp .

You copy it to the avd device folder ( %HOMEPATH%\.android\avd\%AVD_NAME%.avd\ ) and rename it to system.img .

Now it will be used at the beginning, and not in normal mode. 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 when creating it.

A more detailed manual in Russian: http://w3bsit3-dns.com/forum/index.php?showtopic=318487&view=findpost&p=45421931




For android 7 you need to perform additional steps: 1. You need to run the emulator manually. Go to the sdk\tools\lib64\qt\lib folder. Run from this emulator folders with the parameters -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 to restart adbd from root:

    adb -s emulator-5554 root

And remount system:

 adb -s emulator-5554 remount 

It can only be credited once per run emulator. And any other reboot may violate the recording mode. Because of this, you do not need to run any other commands with remount, for example mount -o remount,rw/system .

Other steps remain the same - load the binary, run the binary as a daemon, and so on.

Image from AVD Android 7 x86 with root: AVD Android 7 x86 with root




If you see an error in PIE when executing su binary, then you are loading the binary file incorrectly into the emulator. You should download the binary file named su.pie inside the archive, but on the emulator it should be named su , not su.pie .

+19
Dec 18 '15 at 17:00
source share

I believe the easiest way is to create an alias for the sh command, for example.

 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.

+12
May 29 '14 at 1:07
source share

Here is my package with everything 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 
+2
Nov 20 '17 at 8:07
source share

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

In Andy (Root Shell) [To retrieve, right-click the HandyAndy icon and select “Term Layer”]

Inside the shell, run the following 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 the SU file. This will replace the newly created SU file. (Optional) Uninstall SuperSU and install Superuser on CWM. Set su binary again. Now root is working!

+1
Mar 10 '16 at 3:52
source share

I tried many of the above suggestions, including SuperSU, and couldn't get them to work, but found something much simpler that worked for my purposes. In my case, I just wanted to run SQLite on the command line. I just created an emulator with an older version of Android (Lollipop) and immediately got root access.

+1
Oct 27 '17 at 13:09 on
source share

Try a different way to resolve this issue.

Use Genymotion instead of the default Android emulator. It was implemented by default. It is much simpler and more like a regular Phone. It is free for personal use.

I found this question because I want to install the Xposed framework in the default Android emulator. This installation requires root and flash with custom recovery (for example, TWRP), both for the Android emulator are complex by default. Finally I used Genymotion, and everything was done in a few minutes.

+1
Jun 05 '18 at 15:16
source share

I just replaced and assigned su attributes for ~ / Android / Sdk / system-images / android-22 / google_apis / x86 / system.img, and now on Android 5. I always have root, even for new systems, 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

0
Oct 10 '18 at 3:22
source share



All Articles