Saturday, February 12, 2011

Creating an android app on an Ubuntu Platform with android SDK and Google's Python Android scripting




Creating an Android app using Ubuntu and PYTHON
Platform OS:
Ubuntu 10.10
Programming Language:
Python - SLA4 Android Scripting
Java JDK
Summary:
The latest mobile application trend motivated me to create an Android app utilizing python, and this will be a great way to increase my python programing skills. I do not have an application in mind yet but as soon as my platform is completed and I am running code on the emulator. I will start thinking about an application to develop.
Steps:
  1. Download the openjdk-6-jdk package for Ubuntu 10.10
    http://packages.ubuntu.com/maverick/i386/openjdk-6-jdk/download
  2. Install the package using  sudo dpkg -i openjdk-6-jdk_6b20-1.9.5-0ubuntu1_i386.deb or you can just use the file browser and click on the package and it will automatically install these packages
  1. Determine if you have this package installed javac -version
  1. javac -version and java -version 
  1. Download the Android SDK “android-sdk_r09-linux_x86.tgz” from the following website  http://developer.android.com/sdk/index.html
  2. Once you have this SDK install use the following command to untar the package on your Ubuntu platform.
  1. tar zxvf android-sk_r09-linux_x86.tgz
  1. Move in the un-compressed directory
  1. cd android-sdk-linux_x86/tools
  1. Execute the following command in the Android SDK folder
  1. ./android
  1. Click on the installed packages options and install all available packages
  1. Then click on the Available packages and select both repositories and install selected. This will provide a wider array of platforms and expecially the Google add on.
  1. Once you have the necessary add-ons just select a platform that you want to develop on and in my case I have chosen - 
  1. Now for the programming portion of this build -  I will only create a simple androd hello world but will work on my official android app.
  2. The first step is to install python capabilities on the android emulator
  1. In the android browser go to the following website and download SL4A
  2. code.google.com/p/android-scripting
  1. Double click on the QR box and it will automatically download on the android simulator and then double click or tap on the SL4A download and you will be presented with the following action - press or double click on the INSTALL button
  1. Once you have the SL4A - locate the installed application and double click on the interface and  you will have the scripting environment.
  2. The next step is to install the python_for_android_r1.apk - Just double click on the link and it start the download and once the apk is downloaded - click on the .apk link and install .apk
  1. After step 15 is performed look for the application on your menu area and select the Install button and the python_r7.zip file will download and extract on your android emulator. These are all of the support file for SL4A and some starting scripts.
  1. Click on the test.py script and select command prompt screen
  1. Run the hello world program and execute the following code :
        
  1. Let get a GUI application running and then I can start thinking about what application I would provide the most benefits.
  2. Created a script with the following code -
import android
droid = android.Android()
droidMsg = “My Test App”
droid.dialogCreateAlert(droidMsg)
droid.dialogSetPositiveButtonTexe(‘OK’)
droid.dialogShow()
resp = droid.dialogGetResponse().result
droid.makeToast(“Later”)
Conclusion
I am ready to starting coding my next application on the Android platform thanks to Google for releasing these features and thanks to my favorite Linux Journal Magazine.