• Python, JRuby on the Android Platform in 10 Steps

No dynamically-typed programming languages on the Android platform?

Python. It is well known that Google frequently uses the Python programming language in many of their production applications, including Google App Engine, which is largely built and extended upon with Python and Java. Up until now, it has been uncommon to use Python scripts on the Android platform. There exists the Android NDK, which allows developers to build performance-critical components of their Android applications in native code, but there hasn’t been many options for those who would like to write Android applications using dynamically-typed languages such as Python, JRuby, Lua, Perl, bash, and even JavaScript.

Enter the Scripting Layer for Android

The Scripting Layer for Android project allows users to run dynamically-typed languages on their Android phones. I gave the package a whirl, and was able to access most of the core functionality such as speech, location, and gdata using the demo scripts included with the package. I was able to run the Python in interactive mode on my emulated Android device. Although I have not tested Sl4A on my actual hardware, which is highly suggested, I found Sl4A a fun and light interface to write some quick, simple applications. The demos also show that complex functionality such as accessing speech, location, and other services can be done using Python and other languages as well on Android.

10 Easy Steps to Running Python or Ruby on the Android

I have taken the liberty of summarizing the steps required to get a Python script or application up and running on your Android device quickly using ASE. This is no substitute for fully absorbing the documentation and becoming fully familiar with the code and capabilities of ASE, but for the impatient it’s a quick way to get Python, JRuby (or most other dynamically-typed languages) up and running fast. To those wondering why I didn’t focus on Perl, Bash, or Lua, in this tutorial, it’s mainly a matter of preference. Feel free to swap the words Python and JRuby with any language you prefer that the ASE supports.

Step 1) Read over the documentation and tutorials at the SL4A Wiki

Step 2) Download the aseXX.apk package from http://code.google.com/p/android-scripting/downloads/list

Step 3) Install the ASE on your device by running

android-sdk-mac_86 msacks$ tools/adb install -s ~msacks/Downloads/ase_r25.apk

Step 4) Click on the ASE application within your Android Emulator

Step 5) Click Menu->View->Interpreters

Android ASE Application (Second on Top Left)

Android ASE Application (Second on Top Left)

Step 6) Click Menu->Add, and then add your Interpreter of choice. In my case, I selected Python

Step 7) The requisite dependencies will automatically be downloaded by the ASE

SL4A Downloading Python Packages

SL4A Downloading Python Packages

Step 8) Create an application in Python on your local machine and push it to your Android device or emulator. Or run in Interpreted mode. In my case I just ran a simple print statement, but there is also a demonstration of test.py, which is a full suite of functions created by T.V. Raman at Google. (Licensed under the Apache 2.0 License).

The Scripting Layer for Android with Python

The Scripting Layer for Android with Python

Considerations and discussion

Will developers be able to package other languages such as Python and Ruby into their Android binaries?
How will this affect code security and static analysis that Google most likely does on their end for uploaded code?


Share and Enjoy:
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • E-mail this story to a friend!
  • FriendFeed
  • HackerNews
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Twitter
  • FSDaily
  • Ping.fm

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply

You must be logged in to post a comment.