Xathrya Sabertooth |
Develop Android App using Python: Set up Environment Posted: 25 Sep 2013 11:09 PM PDT A common misconception about developing for the Google Android Platform is that you have to write your code in the Java programming language. The truth is you actually have many options. OK, aside of NDK (Native Development Kit) using C/C++, you can develop application using Scripting Layer for Android. The Scripting Layer for Android (SL4A) brings scripting language to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. Started out as 20% project by Google employee Damon Kohler, the project now supports Python, Ruby, Perl, Lua, JavaScript, BeanShell, and more platform. This article is part of series of articles explores how to use Python and Scripting Layer for Android (SL4A) to build application for Android. This article will discuss about how to setup environment for developing Android app using Python. What I use for this article are:
Note that I use Slackware (Linux) and Windows as proof of concept. You can either use one or both but I will try to make it as general as possible. Who have Use SL4A?Many! But notable users are:
Why Python?So the first question, why python? Python is a great tool for writing both simple scripts and complex, multi-threaded applications. The great thing about having Python on Android is the opportunity to use the untold thousands of lines of code already written and freely available. Python is an easy language to learn if you’ve never used it before, and you will find many resources available on the Internet to help get you up to speed. Obtain MaterialsSL4A has several packages. But for our goal, we need only two packages: core SL4A and Python for android. Both you can download from SL4A download site. Here what you need (last version per September 26th, 2013): As the popularity of Python for Android grow, the project has been forked to new project which stand side to SL4A. You can visit Python for Android project page and download their latest release. If you don’t have Oracle JDK, Android SDK, and Python yet then grab them. Installation and SetupOn Android DeviceInstall SL4A on Android device. This process is similar to any other Android application installation process. Before installation, make sure you enable the “Unknown sources” option in your device’s “Application” settings. Open up terminal / your command prompt. Make sure you can access adb from your “$ANDROIDSDK/platform-tools” path. Connect your phone to your machine and invoke following commands: adb install -r sl4a_r6.apk adb install -r PythonForAndroid_r4.apk To make sure Python for Android installed, see your application list and search for Python for Android. It should has following user interface: Tap on Install to install the interpreter needed. Your phone then downloading some extra packages. To verify, open application named SL4A on your launcher. See the “Interpreter” on “View” menu. You should see Python 2.6.2 there. On Development MachineThe SL4A needs Oracle Java Development Kit (JDK) and Android Software Development Kit (SDK). All of them must be provided before we install SL4A. We also need to install Python. Note that all dependencies should have correct architecture based on your machine. As I use 64-bit machine, I will need to install the 64-bit version. At this point, I assume you have all the dependencies installed. Reference:
TestingLet’s test the environment by creating a simple hello world project. Write this on your development machine as hello.py: import android droid = android.Android() result = droid.makeToast('Hello, world!') Then send it to your Android phone. The simplest way is using adb. adb push hello.py /sdcard/sl4a/scripts/hello.py Now run the script by running SL4A. You should see lot of python script in the list. Our script is hello.py, just tap it to run it and you can see the toast. You can also create a simple script to upload your script: Appendix A: SL4A FunctionalityThe SL4A has following functionality which can be used on Python:
|
You are subscribed to email updates from Xathrya Sabertooth To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Tidak ada komentar:
Posting Komentar