Installing the Android Scripting Environment on the Android Emulator

Update:  I have a newer post here describing how I got the SL4A installed on an actual phone.  More work than I expected…

Based on my previous post, the thought of being able to run Python on an Android Device via the Android Scripting Environment seems… enticing.  However, I personally do not own an Android Device, nor have plans to get one anytime soon (ah, love those AT&T contracts…).  But there is the Android Emulator which I can run on my PC, why not use that in the meantime?

What I expected to be easy turned into quite a quest.  But I got it working, and the steps are listed below.  Specifically, this is a walkthrough on installing the Android SDK, creating an ‘Android Virtual Device’, launching the Android Emulator, installing the appropriate scripting language data on it, and running that language on the emulator.  This was done on a WinXP system.  I should also point out that this was my first foray into anything Android related, so I am quite a bit of a noob at this point.  My knowledge does not stretch far beyond this tutorial :-)

Finally, while my goal was to get Python running, you can use these steps to (presumably) get other languages (Lua, Perl, jRuby, BeanShell, Rhino) installed as well.  My tutorial below will be based around Python and its associated dependencies, but you should be able to mentally replace that with the language of your choice.

#1: Install the Android SDK:

Based on this post, I got the SDK installed.  I’d recommend you follow it as well.  You can stop at their “Step6: Create a new Android Virtual Device”, since that’s what we’ll cover below.  Note that this install process was done with version Android v2.0, can’t vouch for earlier versions.

  • It ended up being installed here:  C:\android-sdk-windows
  • Not sure of the importance, but I read online that you need to add a Windows System Variable named ‘SDK_ROOT’ with the value of the tools dir in the SDK install location, which for me is ‘C:\android-sdk-windows\tools’

#2: Create an Android Virtual Device (AVD):

  • I first created a shortcut on my desktop to this bat file which I use to launch the ‘Android SDK and AVD Manager’:
    • C:\android-sdk-windows\tools\android.bat
  • Under ‘Virtual Devices’, I created a new AVD, named it ‘ASE_test’.  Specifics in the image:
  • createNewAVD
  • After creation, pick the AVD in the ‘List of existing Android Virtual Devices”, and “Start…”
  • This will launch the Android Emulator:
  • emulatorScreen
  • Getting closer…

#3: Install the Android Scripting Environment (ASE):

It’s important that the Android Emulator is open (& unlocked) and running while the below steps are performed.

I read a lot of documentation about making a disk image of a memory card that the AVD could load in place of a real one.  I spent two hours trying to get this to work… it just didn’t happen.  Then I learned that you can install the ASE via the ‘Android Debug Bridge’ (adb) in a shell, and everything got a lot easier…

  • Download the ASE, and appropriate scripting language data.  Find them at the ‘Android Scripting’ download page here:
  • These files specifically: (note: since the time of authoring this post, the below apk and zip files have been updated… be sure to grab the latest versions)
  • After downloaded, for convenience, copy them to your SDK\tools dir:
    • C:\android-sdk-windows\tools
  • Install the ASE:
    • Make sure the Android Emulator is up and running (& unlocked).
    • In an OS shell, change directory to the SDK\tools directory.
    • Execute these commands to install the ASE on the emulated Android Device (running in the background):
      • C:\android-sdk-windows\tools>adb install ase_r14.apk
    • Then, use these commands to copy the Python data to the virual sdcard on the emulator:
      • C:\android-sdk-windows\tools>adb push python_scripts_r0.zip  /sdcard
        C:\android-sdk-windows\tools>adb push python_extras_r0.zip  /sdcard
        C:\android-sdk-windows\tools>adb push python_r0.zip  /sdcard
    • That should do it!  Your shell should look something like this when complete:
      • C:\android-sdk-windows\tools>adb install ase_r14.apk
        570 KB/s (127785 bytes in 0.218s)  pkg: /data/local/tmp/ase_r14.apk
        Success 
        
        C:\android-sdk-windows\tools>adb push python_scripts_r0.zip  /sdcard
        133 KB/s (4280 bytes in 0.031s)  
        
        C:\android-sdk-windows\tools>adb push python_extras_r0.zip  /sdcard
        502 KB/s (2460097 bytes in 4.781s)  
        
        C:\android-sdk-windows\tools>adb push python_r0.zip  /sdcard
        360 KB/s (1726792 bytes in 4.671s)

#4: Configure the ASE:

At this point, the ASE should be installed in the running Android Emulator, and the Python data (or whatever scripting language you’re using) copied to the virtual SD card.

  • Expand the Application Tab.  You should see the “ASE” icon.  This means a successfull .apk install!
  • aseInstalled
  • Select the ASE icon.  This will launch the Android Scripting Environment, and give you a screen saying “Start adding scripts and Interpreters by pressing the menu button”.  We need to install the Python interpreter, so, press “MENU”.
  • Along the bottom of the UI three buttons will pop up.  Press the middle one “Interpreters”.
  • This will clear the screen with only one option; “Shell”.  Press the “MENU” button again.
  • New buttons along the bottom, press “Add”
  • AH, a big list of stuff to install!  Scroll down to ‘Python 2.6.2’ and press it.
  • This will start an extraction process, and you should see it extract the various Python .zip files you had put on the virtual SD card earlier.
  • Now the UI has two options, “Shell” and “Python 2.6.2”.  Press Python…
  • This launches a Python shell.  Success!
  • pythonShell
  • Hitting the return button twice will take you to another menu that has all the default Python modules previously installed: notify_weather.py, saychat.py, etc.  Press ‘test.py’:
  • This will run that module, executing a variety of test suites on the emulated device.
  • Pressing menu can take you into a module edit mode as well:
  • testPy
  • That’s pretty cool… 😛

In Conclusion…

What to do now?  First step, will be to go over all this info on the ‘Android Scripting Groups Wiki’:  http://code.google.com/p/android-scripting/w/list

I have to say, interaction in the emulator itself  is really slow, with lots of lag.  I also had a weird issue where all the text I tried to type was being converted into Japanese.  I had to go into my emulator’s Settings -> Language Keyboard -> And uncheck the first two options under “Text settings”.  I don’t know what they are, since they’re in JAPANESE.  But that fixed it.

Thus, it begins.

Index of reference pages:

These are pages I pulled a lot of info from to figure all of this out:

Android anyone?
Two new books added to the library...
  • Trackback are closed
  • Comments (48)
    • Ravenger
    • November 26th, 2009 12:50pm

    I saw your post the other day on Google Groups. Many people, including myself, have been wondering the same thing — How to install ASE in an emulator. It would seem which ever forum you ask how to install it, all you get are the standard replies, “Read the documentation,” “Click here,” and “You’re doing it wrong.” Of course, none of those replies actually tells you how to install it. I too have read lots of documentation regarding ASE, and there is plenty of it to read. However, none of it actually explains how to install ASE in an emulator. It’s not that I’m stupid, it’s just that far too many people assume you have as much knowledge as them and often time those assumptions bypass important processes that the writers have taken for granted. You, thankfully, have not.

    Thank you for the detailed write up. I’m really excited and looking forward to installing it. Unfortunately, it’s Thanksgiving Day and I found your article too late to attempt an install before family start arriving. Just know, over turkey and mashed potatoes, your article will be on my mind.

  1. Hey, thanks for the reply. I wrote that post exactly for people like you, since you sound exactly like me: Similarly, I often feel like there are multiple parts to the process, and it’s that middle part that’s missing:
    #1: Install the base software (well documented).
    #2: Configure the software (zero documentation).
    #3: Start doing stuff with the configured software (lots of web pages, newsgroups, etc).
    It was my hope with this to fill in #2.
    It took me several hours to figure it all out; my wife came in a couple times wondering why I was cussing at the computer 😉 I hope you get it working too, happy Thanksgiving.

    • Ravenger
    • November 26th, 2009 7:52pm

    Extremely tired and stuffed of Thanksgiving turkey, I couldn’t wait until morning to try the install. Worked like a charm!! Specifically, I was after a perl install rather than python as used in your write up. I just substituted the .apk and supporting zip files (as found in the first link of #3 in your write up above) with the ones designated for perl and Bingo! I’m in business running perl scripts. In addition, I will be making a Virtual Device (AVD) for each of the different options available, i.e., lua, python, etc. Thanks again.

  2. Excellent. I think I’ll change the post a bit to call out that while I did Python install, they can be successfully substituted for others.

  3. Akeric, I am getting a Motorola droid for Christmas and thought I’d get a jump by installing the SDK and scripting environment when I saw your detailed instructions. No problem with the SDK install, but I must have missed something somewhere wrt the emulator.

    When you talk of a “command shell” I assume that is the little black box I used to know as the “DOS window”. I change the local directory to match where my ASE install package resides but attempts to “run” adb install ase_r14.apk result in an “unrecognizable” command message.

    Also, you say to have the Emulator running in the background and “not locked”. I am not sure how I would either lock” or “unlock” the emulator at this point.

    I’m sure I missed something somewhere, but am at a loss to figure out what.

    FYI: I’m running Windows XP Home, SP3

    Any additional hint you can provide would be much appreciated. BTW, I am the “idiot” designers try to proof their stuff from…………..

    Clark

  4. Let’s see what we can do 😉

    Yes, the Command shell is the “black box thingy”. Sounds like you’ve already found it, but the easiest way in Win2K is go Start Menu -> Run -> and at the prompt type ‘cmd’ (no quotes). That will fire up the shell. Then you ‘cd’ to the dir in question to run the applications.

    For the ‘unrecognizable’ command message, it usually means that you’re trying to execute a command that is either: A, not part of the Windows PATH system variable, or B, a command tied to an executable, but you’re not in the dir where that executable lives. My guess your problem is B: In the shell, you’ve changed directories to a dir where you *think* the ‘adb’ application lives, but something went wrong (you’re in the wrong dir). While you’re in that directory, you can type ‘dir’ to see a list of all files in there. Make sure adb is in there. Again, on my box with the default install that dir is:
    C:\android-sdk-windows\tools

    Finally for the “unlock” issue, I simply mean this: When the emulator runs, you first need to “unlock” the emulated phone by dragging the ‘unlock slider’ at the bottom of the screen from left to right (same thing you do on an iPhone to unlock it). I found that if this wasn’t done, I couldn’t use adb to update the phone.

    Good luck!

  5. Eric, thank you very much for the help. Somehow my install managed to scatter the files into several directories. Anyway, a reinstall went well and I have now gotten the SDK installed and the ASE running in the same directory.

    Everything matches your web site example up to, and including, launching of the Python shell. There do seem to be a few missing steps between getting the Python shell (“Success”) and “Hitting the return button twice…”. A bullet item text may be hidden under the emulator screen image. But after entering the “import sys” commands as illustrated on the web page I do get the rest of the screen to display as shown. But after “Hitting the return button twice…” I just get another ‘>>>’ prompt. I never see a “menu”.

    Clicking “MENU” on the emulator gives me a Menu with 4 choices:”Preferences”, “Reset”, “E-Mail” and “Special Keys”. It does not switch me to the module edit mode.

    I did install the SDK slightly differently: I only installed android 2.0.1, the associated Google API, the Windows USB driver and the SDK documentation. I did not install the earlier android/Google packages.

    Again, any hints would be appreciated…..I seem so close.

    Clark

  6. Hmm…. at this point I’m not sure why your emulator menu would be different than mine, I definitely get a different set of options than you when I hit the menu button, I still get similar results as described above. But honestly, I’m not saying what I have up there is the ‘definitive guide to using the emulator’, it’s just how I interacted with it on first try. I should also point out I think that whole ‘menu’ system is really clunky and non-intuitive… it took me a while to just figure out the little bit I have up there. I’d recomend you just ‘play’ with it and figure out how it works based on trial and error, that’s all I did.

    However, I think the main goal is that you actually got it installed and can launch a Python shell in the emulator. You may want to ping the usergroups for any issues with interacting with the outlying software itself: http://groups.google.com/group/android-scripting

    Glad you got it working.

    • Ravenger
    • December 8th, 2009 10:39pm

    FYI: The unlock bar doesn’t always appear in the emulator. I found that the first run after a Windows reboot usually causes the emulator to just go right into the home page bypassing the lock/unlock screen. I also noticed that the first line install (the apk file) usually fails when the emulator jumps past the unlock screen. Just retype the install line again and everything gets unlocked properly.

    Another thing I noticed after updating the library was that Android 2.0.1 has a different unlock screen than earlier versions.

    @Clark. In Windows, look under accessories for “Command Prompt.” That will bring up the DOS command window as well. CD (change directory) to where your SDK resides and once the cursor shows you’re in that directory, then run your adb commands. Also, to answer your other question regarding the Menu. You’re in the wrong window (you’re in the command prompt screen for the particular interpreter that you loaded, i.e., python, perl, lua, etc.). Once you get to the command prompt of the interpreter that you installed, back out one window (use the button to the right of the menu button on the emulator). Then you’ll see the message “Terminal Killed” and see Shell and whatever interpreters you have installed. If you back up one more window, you’ll see all of the sample scripts that were loaded and available. Back up one more window and you’re back at the home screen. Once everything is setup, you can also start at the home screen, run the ASE and the first screen you come to is the list of all of the scripts available to run (sample scripts mentioned above).

  7. Thanks for the great post – it was very straightforward, easy to follow and I now have it running. Two things,1/ you call to download perl_scripts, I think you meant python_scripts

    And 2/ it is important to note this only works with Android 2.0 emulator. I tried 1.5 and 1.6 and it would not load the apk.

  8. Oops! Good catch on the incorrect link. And I updated the blog with the 2.0 comment. Thanks.

  9. One more thing that helped me. To load a python program I developed onto the emulator and have it appear in the list of scripts, I had to use the following:

    adb push ‘filename.py’ /sdcard/ase/scripts/’filename.py’

  10. Nice. I honestly haven’t gotten that far yet. But now I know what to do 😉

  11. Really a great article.

    • Wolfgang Eigner
    • January 31st, 2010 10:10am

    Thanks a lot for going through that and writing it up so clearly for all of us.

    Let me just add, for those who are reading this after me, that the actual version of ASE is now r16, so if you download the .apk file, just change the 14 into 16 in above explanation.
    Python is now in r2 instead of r0, but you don’t need to download and push those files anyway, ASE automatically gets them via internet and unpacks them when you add the pyhton interpreter.
    In other words, in step #3, all lines that have the word “python” in them can be ignored now.

    Thanks again

    • Varsha
    • February 1st, 2010 8:50pm

    Just Wowww!!
    Thanks a lot for giving such a detailed and easy explanation.

  12. Thanks for the tip Wolfgang. I’ve updated the post to reflect this.

    • Adrian
    • February 5th, 2010 1:53pm

    Thanks, nice job. I’ve been waiting for a great language to play with on Android Emulator and phone… and now I can.
    :)

    • ram
    • February 25th, 2010 4:45am

    i want to find out how to unlock emulator from cmd

    • Mårten
    • February 26th, 2010 12:45am

    Hi,

    I notice you installed this on a Win2k system.

    When I do that and I try to start the emulator I get a WS2_32.dll error
    “The procedure entry point freeaddrinfo could not be located in the
    dynamic link library WS2_32.dll”
    Did you get this error, if so, how did you circumvent it?

    The reason I ask is that the freeaddrinfo was only added in Windows XP and later and is not available in Win2k

  13. AH. It’s because I had a typo :( I installed it on a winXP system, not win2k. I’ve updated my blog, sorry about the misdirection.

    • T. S. Ferreira
    • June 19th, 2010 1:08pm

    I tried to follow your instructions on my Mac OS X. No problems including the command:

    adb install ase_r25.apk

    but when I execute:

    adb push python_scripts_r7.zip /sdcard

    I get the answer:

    failed to copy ‘python_scripts_r7.zip’ to ‘/sdcard’: Is a directory

    Any hints?

  14. I unfortunately have no experience with this on the Mac (or using Mac’s in general). Maybe some other reader will have an idea.

    • T. S. Ferreira
    • June 21st, 2010 6:12am

    I found a much simpler way to install ASE and any of its scripting languages on an Android phone or on its emulator. Just follow these steps:

    (1) Using phone’s (or emulator’s) browser download from http://code.google.com/p/android-scripting/downloads/list the latest version of ASE application (at this moment ase_r25.apk).

    (2) Slide down the notification page and you will see a line for this download: just click on and it will ask whether you want to install it — go ahead.

    (3) Open ASE after the installation is finished.

    (4) Click: Menu -> View -> Interpreters (only “Shell” will be exhibited)

    (5) Click: Menu -> Add: a list of interpreters (Python, Ruby, etc) will be shown.
    Choose your favorite and follow the instructions. In case of Python (the only one I installed) it can take a few minutes.

    It worked beautifully!

    — tsf

    • Sobin
    • July 9th, 2010 10:26pm

    Hi Akeric

    I have installed the ASE on the emulator. After installing i am getting the ASE icon. On launching it, i can see list of scripts.
    I went to
    -> Menu -> Interpreters -> Python2.6.2

    But i am facing a different issue.

    /data/data/com.google.ase/python/bin/python : not found

    Any solution

    • ausmented
    • July 24th, 2010 1:40am

    I’m getting “ImportError: No module named collections” when I run any script:
    File “/sdcard/ase/extras/python/android.py”, line 17 in import collections
    Any fix ideas gratefully appreciated.
    python r7
    python scripts r8
    pyhton extras r8

    • dheiser
    • August 2nd, 2010 1:58pm

    This is a good post. It has really helped, but I hit a wall.

    I am trying to install Python and I get a message that the SDCARD is read-only…

    C:\TEMP\android-sdk-windows\tools>adb push python_scripts_r0.zip /sdcard
    failed to copy ‘python_scripts_r0.zip’ to ‘/sdcard/python_scripts_r0.zip’: Read-only file system

    When I execute “adb shell”, then “ls -l” I see this…

    d——— system system 2010-08-02 19:45 sdcard

    When I execute “chmod 777 sdcard”, I get this…

    Unable to chmod sdcard: Read-only file system

    • naveen
    • October 10th, 2010 2:03am

    Thanks for the detailed description of steps involved in installation and collection of links required for the same. I followed the steps mentioned here exactly in the same sequence and it worked quite well for me.

    Thanks again

    • Ravenger
    • November 11th, 2010 8:51pm

    I recently installed a new ROM on my rooted Droid and needed to reload ASE and all of my scripts on the phone again. I kept missing a step and couldn’t remember exactly how to install it correctly, so, of course, I Googled it and this article popped up. Ironically, and even spookier, it was pretty much exactly a year ago when I first found this very article and loaded ASE the first time. See my replies above.

    I see now that downloading it directly from the phone’s/emulator’s browser has made it even simpler as are the various interpreters. See T.S. Ferreira’s reply above.

    Thanks again for the great article. It helped me out for a second time.

  15. It’s the gift that keeps on giving 😛 And yah, you were the first reply! :)

    • Nitin
    • December 8th, 2010 11:37pm

    Hello
    I am getting error in this command “C:\android-sdk-windows\tools>adb push python_scripts_r0.zip /sdcard” and the error message coming is this one “failed to copy ‘python_scripts_r0.zip’ to ‘/sdcard’: Is a directory”. Can you help me on this.

    Thanks

    • tredsa
    • January 19th, 2011 1:30pm

    I’ve the same problem

  16. I’ve switched operating systems and computers since I originally authored this post. If someone else has a solution to the problem, please post it :)

    • tredsa
    • January 19th, 2011 2:12pm

    I followed the rest of the instructions and it worked

    • Joe
    • January 24th, 2011 10:03pm

    adb push needs another slash at the end “/sdcard/”
    Anyway, I was installing PHP and sl4a automatically downloaded and installed it when I selected it from the list.

    • Gordan
    • August 16th, 2011 6:33am

    I have a problem when im start a python i see this error:

    /data/data/com.google.ase/python/bin/python: permissin denied
    $
    How can i fix this ?

    • Marttini
    • September 5th, 2011 10:16pm

    I could kiss you bro!

    Missing the SDcard configuration step on step #2 got me off track and cost me a whole day,

    but, finally I managed to get it up and running!

    I can’t thank you enough!

    • Marttini
    • September 6th, 2011 7:55am

    @intbt
    Very helpful tip!
    Thanks a million!

    • alias
    • October 16th, 2011 4:44am

    Hi, all

    how to install sl4a and python on android 2.3.3 for mobile
    samsung galagsy 2

    thank you.

    • alias
    • October 16th, 2011 4:48am

    Hi, all

    how to manually install sl4a and python on android 2.3.3 for mobile
    samsung galagsy 2

    for know i have these pakges:-
    1- sl4a4.apk
    2- python_for-android_4.apk
    3- examples.zip
    4- extract.zip

    thank you.

    • skip
    • November 6th, 2011 2:06pm

    The gift keeps on giving. I used your procedure (with some liberal
    interpretation) to install sl4a and python on a gingerbread AVD –
    even the comment on Japanese language settings.

    Thanks

    • Jennie
    • December 17th, 2011 11:22am

    If you’re getting this error:
    “failed to copy ‘python_scripts_r0.zip’ to ‘/sdcard’: Is a directory”

    try the same command you’re trying earlier but this time with a forward slash added to /sdcard, meaning replace /sdcard with /sdcard/ and keep the remaining part of the command as earlier and it’ll work like a charm.

    • Tuan
    • January 25th, 2012 6:55pm

    Thanks so much.
    I followed step by step and it works now.
    Only one thing should edit is that /sdcard/ instead of /sdcard

    Many thanks again.

    • himraj13
    • February 1st, 2012 8:56am

    now days, you can use,

    PythonForAndroid_r4.apk

    and

    sl4a_r4.apk

    instead of ASE. both available at

    http://code.google.com/p/android-scripting/downloads/list?q=label:Featured

    • DJ
    • February 14th, 2012 2:18am

    awesome man, i am really thankful to you for posting such a knowledgeable post.

    • Sam Quiring
    • March 7th, 2012 2:31pm

    himraj13,

    You said PythonForAndroid_r4.apk, but over on the PythonForAndroid web page (http://code.google.com/p/python-for-android/downloads/list) they have:

    PythonForAndroid-r7b1.apk

    This is the first pre release of Py4A, main difference between this version and previous ones is that now you don’t need to install Py4A once the APK is installed.

    Do you know if -r4 is newer/older than -r7b1?

    -Sam

    • Naveen
    • September 14th, 2012 2:07pm

    Thanks for this one place reference for setting up python. It was really helpful to me in setting up android dev env for me.

  17. Glad it’s still valid! Can’t believe I authored it going on three years ago :)

Comment are closed.