Saturday, May 21, 2011

Test root apps on Android Emulator



The Android Emulator provide a powerful way to test Android applications. But it not allow you to test root apps because you can't get root privileges via su on the Emulator, although it's possible via adb shell.
So if you want to test root apps you have to get a rooted emulator. It's mean a su binary and optionally the superuser app which allow you to manage root apps.



Here is the list of commands you have to run while the emulator is running : 

 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.
To install superuser persistently :
 adb install superuser.apk 

[Update April 2012] : This tip doesn't work anymore, see comments for more information

12 comments:

  1. Hi there..! It's all fine. That commands shows no error. But, when i tried to install shootme apk(which needs root access) has installed successfully,But it is not running in my emulator and it show that Need root access to run this application. How can i determine that my emulator is rooted..?

    ReplyDelete
    Replies
    1. Hi,
      What you have done should work. But I test it today and it doesn't work anymore.
      The only diference between my today's test and when I used this tip in May 2011 is the sdk version (which is different from the Android version). Back in May 2011 I guess I used the sdk r9 or r10 (my current version is r18).
      For the record, with which version of the SDK do you try and what is the AVD Android version ? For me it's sdk r18 and AVD 2.1 and 2.3.3.

      If you have the time you can test this :
      1) Download a previous sdk version (ideally r9 or r10)
      2) Download the package for Android 2.1 or 2.2.
      3) Create a new AVD 2.1 or 2.2
      4) Run the newly created AVD
      5) Perform the described steps
      6) Install your APK and test it

      Ping me if you have more informations on this issue.

      Delete
    2. This works for me:
      - sdk rev 18
      - avd target: Android 2.3.3 (API level 10)

      Delete

    3. 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

      where should i check these commands.when i tried it in cmd,command doesn't finish executed.

      Delete
  2. I have been intelligent for hours and I haven't gone through such awesome stuff.
    news

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete

  5. I’m glad to locate so much of informative data in your blog.
    Us Technical Support

    ReplyDelete