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’:
- Under ‘Virtual Devices’, I created a new AVD, named it ‘ASE_test’. Specifics in the image:
- After creation, pick the AVD in the ‘List of existing Android Virtual Devices”, and “Start…”
- This will launch the Android Emulator:
- 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)
- http://android-scripting.googlecode.com/files/ase_r14.apk (The ASE itself)
- If you want to install Python, these are the files you’re after. If you’re using a different language, find similar files in the same download page. (Note: Based on blog reply below by Wolfgang, it explains this step may not be needed based on ASE updates. I have yet to test, so I’ll leave this info here for the time being)
- After downloaded, for convenience, copy them to your SDK\tools dir:
- 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):
- Then, use these commands to copy the Python data to the virual sdcard on the emulator:
- That should do it! Your shell should look something like this when complete:
#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!
- 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!
- 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:
- That’s pretty cool…
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: