Skip to content

Posts tagged ‘asl’

11
Nov

Making releases for python programs in android

It’s been a while since I lastest got Digenpy for android ready, so I decided to take a look at it again and re-do it. After I finised most of the work, I realized I didn’t have a build-and-test apk system, so I’ve built one.

Here are the steps I followed, as described by android documentation:

  • Download android sdk
  • Get java development kit (sun-java6-jdk in debian. Only available in debian stable at this time)
  • Launch “android” executable from sdk tools/ directory and specify it to download the APIs you want, and the platform tools.
  • Generate apk with ant *
  • Align apk with zipalign from tools directory *
  • Set up a virtual machine in emulator *
  • Launch app in emulator *

* I’ve made a little script, hosted here , it also can do debian packages and windows exes (I will talk about it in my next article). After apk building it launches android emulator to test it.

Let’s get all of it togheter. We need to install a few things and configure the script.
First of all, we’ll need to install android SDK on a good path, like /usr/local/share/android-sdk.

$ wget http://dl.google.com/android/android-sdk_r15-linux.tgz -O - |tar xvzf - 
# mv android-sdk-linux /usr/local/share/android-sdk

Then, we install sun-java6-jdk, only debian stable is covered here.

# apt-get install sun-java6-jdk sun-java6-jre

Finally, we’ll install the android platform tools and sdk, launching (as root) the android app.

# /usr/local/share/android-sdk/tools/android

Inside there, we’ll select an API (I’ve chosen 10) and the platform-tools and SDK-tools.

Android tool

To be able to emulate, first we’ll have to create the config for an emulator, we’ll do it trough tools/Manage AVDs

Android virtual device manager

Now, we will download the template for android-python apps, uncompress it, and put our script on raw/res/script.py, then execute package_generator script.

wget http://android-scripting.googlecode.com/hg/android/script_for_android_template.zip
unzip script_for_android_template.zip
mv hello_world.py raw/res/script.py
Package_generator.sh apk

And there we have it: It will generate a nice APK, and launch the emulator with the apk installed so we can test it.