Hello developers.You are thinking that why i have started this blog with part-2.Its obvious that you are wondering where's the part-1 of this tutorial.I wanted to write tutorial from the inception but before me Paul Ferrill wrote the part-1 of the tutorial.You can read the part-1 from here . Paul explained brilliantly about setting up the sl4a development environment.So before reading this tutorial you should follow the Paul's blog because i am starting this tutorial from where Paul ends his tutorial.Paul explained almost everything in his blog to setting up sl4a development environment except development with eclipse.If one is serious to develop application using sl4a then one should have any IDE to manage his/her project and its really hard to manage big applications without any IDE.With eclipse one can not only develop and sign his/her application but also debug the application easily.So its necessary to set up the sl4a environment with eclipse(or other IDE e.g intellij idea but I am a fan of Eclipse that's why I am using here Eclipse).
Before starting I am assuming that you gone through the Paul's blog and set up the environment till the python interpreter.Now first you should go to http://mercurial.selenic.com/wiki/Download. Download the svn.I have download the Mercurial-2.0.2 (32-bit msi) because i am working on windows.You can choose the installer according to your platform.Install the msi installer.After installation you can see the C:\Program Files\Mercurial folder in your system.After that download the eclipse from http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/indigosr1. I have downloaded the Windows 32-bit from the right side column.Eclipse will take time to download depends on your internet speed.Put the eclipse to a specified folder which you can access easily in your system.I have put eclipse folder here - E:\software\eclipse3.7.Now go in eclipse folder and launch the eclipse.exe . You will get the following view.
If you click the Overview item, it will open another screen with four topics: Workbench Basics, Java Development, Team Support, and Eclipse Plug-In Development.The only item of any real importance to this book is the Workbench Basics topic. Clicking this item will launch the Eclipse Help system, as shown in Figure . If you expand the Getting Started section, you’ll find a detailed tutorial covering all the basic operations you’ll need to know to navigate through Eclipse. It will be well worth your time to explore the tutorial material if you haven’t worked with Eclipse before.
Now we need to install the ADT(Android Development Tool) plugin in eclipse.For installing it go to the Help in tab bar click on Install New Software.. You will get dialog box like in the following picture.
Put the link http://dl-ssl.google.com/android/eclipse/ in place of type or select site a site in edit box. Click on Add button to add the link in library.You will get a dialog box asking for name and location.Put the name-ADT Plugin and location-http://dl-ssl.google.com/android/eclipse/ ,click ok. After putting the link http://dl-ssl.google.com/android/eclipse/ in edit box will some tools in Name field like the following picture.
Select all the tools and click on next button.In next screen again select all the tools and click next button.It'll take time complete so have some patience.
After that you have to install the python plugin in eclipse. Follow the same procedure we used to install ADT Plugin. Put the link http://pydev.org/updates in edit box.Select all the tools in name field,click next.In next screen again select all the tools and click next.It'll also take some time to install it.
Now go to Window=>Preferences,click on Android put android SDK path in SDK location.My SDK location is:-C:\Android\android-sdk.
After that click on PyDev=>Interpreter-Python.In the Name field click on New button,a dialog will open and ask for Interpreter Name: and Interpreter Executable.Put Python26 in Interpreter name and browse the python exe stored in your system.I put C:\Python26\python.exe in Interpreter Executable.Hit ok, and again ok.
Now you need to create a clone of the latest sl4a repository.Create a folder in your eclipse workspace, I have named it Python_Android.Open the command window.Go to the directory Python_Android using cd command.This my path in which i am going to clone the repository :- C:\Documents and Settings\Gaurav\workspace\Python_Android>
Type the command:- hg clone https://rjmatthews62-android-scripting.googlecode.com/hg/ hit enter,and some time later your clone will be there. The repository gets updated regularly so use 'hg pull -u' to get and update the latest repository. Exit the command window.
Open Eclipse and click on File/Import/General/Existing Projects into Workspace/Next and Browse to the cloned directory. Click on Android/OK then select all and click Finish. Your screen should look like this (with lots of errors):
Go to Project=>Clean,select Clean All Projects radio button,hit ok.This will vanish all the errors.
All these projects now comprise a working clone of SL4A. To turn your script into an APK make a copy of ScriptForAndroidTemplate (right click/copy then right click/paste into the same area). A new project will appear with the name Copy of ScriptForAndroidTemplate. To connect this project to your clone of SL4A double click on it, right click on build.xml /Run As /Ant Build. Rename the project using Refactor/Rename to whatever name you choose for your project and Refresh/Clean/Build the project.
Connect your phone to the PC via the USB cable, press menu, click settings/Connect to PC/Default connection type/Charge only/Done/ then press Home. If you haven't got a suitable phone set up an emulator in the Android SDK and AVD Manager (but be aware the emulator may or may not start at the first attempt and can take 10 to 20 minutes to start working the first time!).
Using the phone press menu again, then click settings/Applications/Development/USB debugging/OK/ then press Home. Windows should automatically find the USB driver for the phone.
With SL4A installed click on your project to highlight it then Run/Run/AndroidApplication/OK. The Console should inform you of the Android launch and a short time later you should see 'Hello Android' appear briefly on the phone (or emulator) which is the output of the default script.
Go in to the project ScriptForAndroidTemplate => res => raw.You can see here a script.py file.Open this file. You can see that project ScriptForAndroidTemplate runs the code written in script.py.
So,you can write whatever code you want in python in script.py and project ScriptForAndroidTemplate runs it for you in android emulator/device.