I’m a developer (among other things). I love Android, but I think Java is cumbersome and annoying. I want to create Android apps using Python. With the Scripting Layer for Android (SL4A) I can create little scripts on the Android device, or I can develop bigger apps using Eclipse and the Android SDK on a “real” computer. About six months ago the Android Java IDE (AIDE) was created. It lets you create real, distributable Android apps (APKs) on Android itself, which is very cool, but you have to do it Java.
Or do you?
Here’s how I combined SL4A’s Eclipse app development process with AIDE to create an Android app and APK on Android, written in Python.
Before we begin, you will need a few Android Apps installed:
- SL4A including the Python Interpreter [Installation HowTo Video]
- The Android Java IDE (AIDE)
OK, let’s get started!
On your computer:
- Download script_for_android_template.zip
- Extract it to `Dropbox/Projects/MyProject`
- Wait for Dropbox sync to finish
- Open AIDE
- Cancel app creation if it pops up
- Select “Download Dropbox Folder here”
- Select “Projects”
- Select “MyProject”
- Tap “Download”
- Wait for Dropbox sync to finish
- Select “Open this App Project”
- Select “res”
- Select “raw”
- Select “script.py”
- Make some changes
- Menu -> Run
Tips and Tricks
- Your Python project lives in the `MyProject/res/raw` folder.
- `script.py` is the entry point of your Python project. You can change this, but I don’t have instructions for doing so yet.
- You can skip the Dropbox part of the instructions and do it all on Android, but if you include Dropbox it is easy to go back and forth between AIDE and Eclipse. I think it’s worth the extra step.
- To create a new file or folder in your project, long-press on an existing file for a file menu.
- The first time someone runs your APK they will be prompted to install Python for Android if they don’t already have it. The process is the same as you went through when installing the Python Interpreter for SL4A.
- If your app refuses to install or run, you probably need to sign it. I suggest creating signing keys in Eclipse on your desktop and storing them in Dropbox. You can then use them from within AIDE. AIDE does have built-in key generation, but it didn’t work when I tried it.
- If “Download” is greyed out when you try to get your folder from Dropbox from within AIDE, that may mean you already have a project with that name in AIDE. Each project name must be unique. You can delete the old project from within AIDE, or rename the new project’s folder in Dropbox.
Where should you go from here?
You should head over to the SL4A Tutorials to learn what all you can do with it.
What’s next for this project?
My goal is to encapsulate this process into an Android app you can download from Google Play. The app will download SL4A Python and the script template, extract it to Dropbox or a location of your choosing, setup the app name you want, and setup the entry point you want (instead of script.py). It will be an easy Android App creator for Python on Android.
I scraped together this information from several sources. These are the big ones:
- “Pro Android Python with SL4A” by Paul Ferrill from Apress
- “How to make an Android app with SL4A and Eclipse” from JohnK
- The AIDE Website
- [2012-07-31] I’ve just learned about the android-python27 and related projects. Using this, you can embed the Python runtime in your application to avoid your users having to download it on first run. There is a lot of cool stuff going on around this project including PyQT support and advanced UIs with Kivy.