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.
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
|The Many Paths to a Solution||Sep 21, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Android Browser Security--What You Haven't Been Told
- Readers' Choice Awards 2013
- Epiq Solutions' Sidekiq M.2
- The Many Paths to a Solution
- Nativ Disc
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Synopsys' Coverity
- Tech Tip: Really Simple HTTP Server with Python
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide