Python for Android
Mobile app development for smartphones is hot. This is no more prevalent than in the Android space where the activity level oftentimes is frenzied. However, when it comes to building a “real” Android app, it seems there's only one programming choice: Java (although it is possible with a lot more work to use C/C++ with Android's Native Development Kit). That said, Google wisely chose the popular Java programming technology upon which to base its Android SDK, which runs a customized VM.
By and large, this has been a smart strategy, as (unlike another popular smartphone) there's no need to own specific hardware and software to get started with app development on Android. All you need is a PC (or laptop) running Linux, Windows or Mac OS X, together with a copy of Java and the free Android SDK. Google provides emulator downloads for all the Android platform releases, and there's even a free plugin for Eclipse to start you off and point you in the right direction.
That's great—assuming, of course, you're a fan of Java. If, like me, you'd rather eat glass than sit down to write some Java code in Eclipse, it would appear that you are out of luck when it comes to implementing your next project on Android. But, this is not the case. There's a rather wonderful project called the Scripting Layer for Android (SL4A) that is bringing scripting languages to the Android platform and providing a working alternative to Java development.
In this article, I walk through the steps involved in preparing your computer for Android development with SL4A, then show how to write, test and run a simple script written in Python on your Android device.
The Scripting Layer for Android is one of the many projects to see life as a direct result of Google's policy of allocating 20% of its employees' time to “pet projects”. Damon Kohler works for Google, and he created SL4A to scratch his own itch when it came to programming Android. SL4A provides a high-level interface to Android's underlying Java technologies, exposing a subset of the API to scripting languages.
To get started, you need a copy of the Android SDK running on your computer, and you need a Java VM. Although you aren't going to program your Android app with Java, you still need a Java runtime upon which to execute the Android emulator, which is part of the SDK. The inclusion of the Android emulator gives you a sandboxed testbed to play in while you create your app.
Before proceeding, you need to make sure a Java VM is installed on your Linux system. On my system (running a recent Xubuntu), I entered the following commands and was told neither program was available to me:
$ javac -version $ java -version
Xubuntu suggested that I might like to use apt-get to install openjdk-6-jdk, which sounded reasonable to me, so that's what I did:
$ sudo apt-get openjdk-6-jdk
If you are running a distro that's not derived from Debian, search your software repository for a similar package and install it before proceeding.
With Java in place, it's now time to get the Android SDK. Downloads of the SDK are available for Mac OS X, Windows and Linux. Pop on over to Google's Android Developer site (see Resources) and grab the latest SDK tarball for Linux.
With the SDK downloaded, simply unpack the tarball within a directory of your choice (the filename you have may be different from the one I use here, but don't worry, yours is likely a later version of the SDK):
$ tar zxvf android-sdk_r07-linux_x86.tgz
This command created a new directory called android-sdk-linux_x86, which I renamed to Android. This newly created directory has a bunch of subdirectories within it. Don't be overwhelmed by all the stuff that's in there. Only one subdirectory is of interest to you at this stage, and it's called tools.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Astronomy for KDE
- Profiles and RC Files
- What's Our Next Fight?
- Understanding Ceph and Its Place in the Market
- Maru OS Brings Debian to Your Phone
- Snappy Moves to New Platforms
- OpenSwitch Finds a New Home
- Git 2.9 Released
- Mark Geddes' Arduino Project Handbook (No Starch Press)
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide