- Subscribe to RSS Feed
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content
All that changed earlier this month with Google employee Damon Kohler's release of his Android Scripting Environment (ASE). Damon converted a popular scripting shell written by Java developer Pat Niemeyer called Beanshell. This environment was selected for several reasons, many of which have already been advertised on the Beanshell website. To quote from the summary of features:
- Dynamic execution of the full Java syntax, Java code fragments, as well as loosely typed Java and additional scripting conveniences.
- Transparent access to all Java objects and APIs.
- Runs in four modes: Command Line, Console, Applet, Remote Session Server.
- Can work in security constrained environments without a classloader or bytecode generation for most features.
- The interpreter is small ~150K jar file.
- Pure Java.
- It's Free!!
In addition to running Beanshell (.bsh) scripts, DamoDamonn also bundled Android-compiled versions of Python v2.6 and Lua v5.1.4 with the package, effectively delivering Python and Lua interpreters for the Android platform. Damon also included special libraries for accessing Android-specific features, such as the ability to call Intents, activate phone features like placing a call and even access other applications like the eyes-free Text-to-Speech (TTS) package and 1D/2D barcode libraries. Beanshell, Lua and Python scripts are included in the .apk installation bundle demonstrating how the 'android' object can be easily instantiated and call upon such functions in script form.
While Damon has promised that the ASE will be available for download from the Android Market, it was exclusively available from the ASE website as of this writing. The version tested for this article was the 0.7 release.
Running a Python Script on Android
Obtaining and installing ASE is straightforward - download the .apk file from the Google Code ASE website, or if you're not in too much of a hurry, wait until ASE shows up in the Android Market and obtain it via the usual means. If installing the apk file, use the Android SDK and run the 'apk install' command from your computer's terminal. Be prepared, however, for a bit of a storage shock. The version discussed in this article consumed a whopping 12 MB on the device - ouch! I had to install it twice, due to immediately receiving a low storage alert with the initial install. It hurt to have to uninstall some treasured Android applications to free up space (including arcade favorite Pac Man), but until ASE has an option to the SD card (or at least store the Python and Lua runtimes and dependent libraries there), ASE users will have to bow to ASE's steep storage requirements.
Figure 1. The ASE consumes a whopping 12 MB of device storage space.
Once installed, activating the ASE is as simple as touching the ASE icon. The opening screen lists demo/starter scripts installed with the setup along with any custom scripts you may have added. From there, scripts can be selected for editing, deleting or, if properly constructed, run as a service (very cool!).

Figure 2. The ASE program icon is shown in the left column, middle row.
While one would hope adding your own scripts to this list would be as intuitive as selecting .bsh, .lua or .py files from a designated directory on the SD card, the current version does not support such easy access. Instead, scripts have to be copied, pasted and saved within the ASE. The ASE saves these scripts in the device's /data/data/com.google.ase/scripts directory. I suppose for root-level access developer phone models, a symbolic link could point to a designated directory on the SD card for easier script storage and transfer between the phone and the computer it's tethered to, but this is cumbersome and might create a security risk. So until a new version that supports easier script access is made available, the following steps are the approach I use to install, run and test scripts within the ASE:
Install ASE via the 'apk install' Android SDK option (or via the Android Market once ASE is posted there).
Install any of the available Android Text editors available from the Android Market (I prefer Paul Mach's TextEdit program).
- Due to the larger screen real estate and much easier input modality, initially author the desired Python script on a computer tethered to the Android phone.
- Mount the Android phone's SD card to the tethered computer's desktop.
- Copy the Python script to Android's SD card.
- Eject the mounted SD card from the computer so that the phone can access the card's contents.
- Locate and open the copied script using an Android text editor.
- Select All and Copy the script's text into Android's cut & paste buffer.
- Launch ASE, press the 'Menu' hardware button and select 'Add' to create a new ASE script.
- Paste the contents of the cut & paste buffer into the new script page.
- Name the file (remember to keep the .py extension), click the 'Menu' hardware button and 'Save' the file.
- Execute the script by selecting the newly saved filename from the list of available scripts.
I have tested several of my own Python scripts and was surprised how quickly the executed on Android, as well as how little effort it took to programmatically wire up Android-specific function calls in my Python scripts. I can easily see how ASE will help me visualize and demonstrate simple GUI app and service ideas before constructing and refining them via the Android SDK.

Figure 3. Editing a 'talking clock' Python script.

Figure 4. Selecting scripts from the main ASE menu.

Figure 5. Executing the 'talking clock' script with user input.

Figure 6. Running a script within ASE's Python interpretter's terminal window.
Limitations
While the current incarnation of ASE provides a very functional developer playground, there are a few annoyances. The most serious constraint is ASE's current inability to easily install and call upon additional library dependencies that may require a more traditional setup.py install (ex: MySQL libraries, etc.). It suspect it might be possible to copy other .py modules like ID3 and HTML/XML tag parser libraries (such as the awesome Beautiful Soup library), though doing so would require additional root-level cat'ing around to copy the file(s) into ASE's /data/data/com.google.ase/python/lib directory. And naturally, while the Beanshell technology delivers a very good shell environment to run Python, Lua and perhaps soon even Ruby and Perl scripting languages, these executables are still abstracted from the Linux OS lying beneath the application process layer that all Android applications such as ASE are sand-boxed into - great for security and stability, not so great for the curious tinkerer and low-level hacker who wants to control every aspect of the system with relatively simple scripts.
Conclusion
The ASE represents a remarkable attempt to bring the ease of popular scripting languages like Python to the Android OS in a very Android-friendly and relatively secure way. While script performance lags somewhat behind native Android applications and the ASE weighs in heavily while trying to multitask other Android programs, the possibilities for prototyping and simple Android utilities are nearly endless. ASE also makes rapid development on Android a reality, along with near real-time code, execute, debug on a self-conntained smartphone platform. For example, when I wrote a talking clock program using Android's SDK, the time it took to learn the nuances of the SDK, the various Android libraries and the various files that make up an Android apk compared to writing the same functionality in a Python script took minutes instead of hours. For Python scripters on the Android platform, the ASE is a no-brainer. For everyone else, the ASE demonstrates yet another reason why smartphone OS's like Android can compete with more comprehensive, heavier weight operating systems. Check it out!
Mike Riley, an advanced computing professional, can be reached via email at mike@mikeriley.com or followed on Identi.ca or Twitter @mriley.





