Having completed my first python script using sl4a on my HTC Desire I decided the next step was to create an APK (Android PacKage) to make it easier to download and run. The process is not that easy (but easier than writing the whole thing in Java) so the following explains how it was done on my PC running Windows Vista:
- Download and install JDK from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Download and install Eclipse Helios: http://www.eclipse.org/downloads/ If you already have Eclipse installed make sure you have the latest updates.
- Download and install the Android SDK http://developer.android.com/sdk/index.html If you already have the Android SDK installed make sure you have the latest updates.
- On start up Eclipse will ask you to create a working directory. Once you have done this install the ADT plugin to Eclipse as follows: Select Help > Install New Software. Click Add, in the top-right corner. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/ If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons). Click OK. In the Available Software dialog, select the checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to be downloaded. Click Next. Read and accept the license agreements, then click Finish.When the installation completes, restart Eclipse.
- In Eclipse click onWindow/Preferences/Android and set the SDK location to where the SDK was installed (probably C:\Program Files\Android\android-sdk-windows).
- Download and install Hg from mercurial: http://mercurial.selenic.com/wiki/Download
- Have a cup of coffee (still some way to go!)
- Create a clone of the latest sl4a repository: Use windows explorer to create a directory where you will store the clone. Hold down the shift key and right click on the directory then open a command window. In the command window type: hg clone https://rjmatthews62-android-scripting.googlecode.com/hg/ 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): [Click on view to enlarge]
Don't panic! First of all you don't need all projects at this stage so right click and Close Project for python, beanshell, jruby, lua, perl, rhino, tcl, InterpreterForAndroidTemplate and Documentation Generator.
Next include ANDROID_SDK in the Classpath Variable list by clicking Windows/Preferences/Java/BuildPathVariables/New. Put ANDROID_SDK for the name and your SDK directory for the folder (probably c:\ProgramFiles\Android\android-sdk-windows).
Now click Project/Build Automatically, then Project/Clean/Clean all Projects/OK. If you get error messages of files missing try Project/Build All without cleaning first. If you still have errors check if any projects have .jar entries in their libs folders which have not yet been added to the build path (right click/BuildPath/add to Build Path if not - but don't put in duplicate entries). Then try Project/Clean/Clean all Projects/OK (and maybe once more if you still have errors). Ignore the numerous warnings.
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. Vista should automatically find the USB driver for the phone.
From Eclipse install your cloned version of SL4A on your phone by clicking on ScriptingLayerForAndroid to highlight it, then Run/Run/AndroidApplication/OK.
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.
Now you will want to tailor your project. Double click your project/res/drawable. Script_logo_48.png is the 48x48 image file that will display on your phone's screen when installed. Replace it to suit your requirements.
Further down from drawable double click values then strings.xml. In the xml display window click on strings.xml and change Dummy Script to your app name (must be less than 10 characters). Right click on the screen and save your change.
Next double click on raw and Refactor/Rename to change the name script.py to your_script_name.py then double click src/com.dummy.fooforandroid/Script.java and change R.raw.script to R.raw.your_script_name and save.
Double click on src and Refactor/Rename to change the package name com.dummy.fooforandroid to your.package.name (you must have at least 2 full stops in the name). Do the same for gen (ignore the warning that the name already exists).
Now highlight your project then click on Project/Properties/Android select your android target and click OK
Towards the bottom of your project list double click on AndroidManifest.xml. Change the package name in the manifest from com.dummy.fooforandroid to your.package.name. Change your minSdkVersion from "4" to suit your android target (this is the API level for your android target shown in Project/Preferences/Android). Uncomment the permissions you require your application to have (take off <!-- at the start and --> at the end).
Right click on your_script_name then open with text editor. Delete the default script, replace it with your own and save. Then Clean/Build/Refresh your project and run it. If all goes well click on File/Export to export your application as an apk. Copy the apk to your phone's sdcard, and use astro to install it.
Eclipse will automatically set your project to debuggable. If you want to distribute your apk open the Manifest Application and set debuggable to False. Then export again. Warn users that the interpreter for your script will also be downloaded when they install the apk.
All finished! Wasn't that easy!!
Excellent stuff.
ReplyDeleteOne thing: you suggest pulling the repository from:
https://rjmatthews62-android-scripting.googlecode.com/hg/
While this is actually the very latest version at the moment, there's no guarantee that it will always be the case.
The official repository is:
https://android-scripting.googlecode.com/hg/
At time of writing, it's in synch with rjmatthews62
I tried hg pull on rjmatthews62 and the official site and got:
ReplyDeleteThere is no Mercurial repository here (.hg not found)!
so I did a clone instead which may not be the best solution to this problem....
ethanthescribe: Robbie Mathews has made so many improvements in such a short time that I thought it better to use his version. I will keep an eye on it to see if this needs changing in the future.
ReplyDeletePeter: I made a mistake (it should have been 'clone' the first time) and I have updated the text. Thanks for pointing it out.
In that case, I did the right thing. Thanks. Although, after cloning (which took some time and several cups of tea) the process created an 'hg' directory as in sl4a/hg and I needed to select this when importing into eclipse as selecting the 'android' directory failed to find any projects.
ReplyDeleteThanks John. It worked for me as far as building SL4A -- I didn't do a script.APK.
ReplyDeleteI did have some trouble that took figuring. My copy of Eclipse was old and the directory structure of the Android SDK has changed a little so ADB wasn't being found. Eventually I did the updates on Eclipse and got it working.
Please add to your instructions that if you already have Eclipse and the SDK make sure they are up to date.
Frank
Frank: Instructions updated regarding your comments, thanks.
ReplyDeletePeter: I got stuck at that point as well. I will try to find out what the problem is.
I created my first apk by following these steps, but the apk failed to run. It crashed immediately after launched. Got any idea?
ReplyDeleteMy script was written in Lua but not Python.
Thanks for all the work...Now I'll never get outside ;-)
ReplyDeleteI followed these posts to the letter and had no problems...It only took 10 minutes to build the sl4a clone over wifi
Having the following error: "ERROR: Unable to open class file /home/derek/workspace/sl4aCloneFiles/hg/android/ScriptingLayerForAndroid/gen/com/googlecode/android_scripting/R.java: No such file or directory".
ReplyDeleteI've tried combinations of cleaning/building, changing build path settings, refreshing, restarting eclipse, switching over to Linux from Windows - nothing has solved it yet. Any ideas how to solve this?
ykhuang, sorry for the late reply. I'm afraid I don't know Lua so I can't really help.
ReplyDeleteDerekM, Have you checked R.java is actually where it is supposed to be? When you imported the projects did you tick 'copy into workspace'? Try deleting gen and then build all (without cleaning or refreshing first). Eclipse seems to have a few bugs in this area and I'm afraid I'm not an Eclipse expert.
I also have R.java missing in 3 places.
ReplyDelete[2011-06-01 15:57:54 - QuickAction] ERROR: Unable to open class file C:\Android\sl4a\android\QuickAction\gen\net\londatiga\android\R.java: No such file or directory
[2011-06-01 15:57:54 - ScriptForAndroidTemplate] ERROR: Unable to open class file C:\Android\sl4a\android\ScriptForAndroidTemplate\gen\com\dummy\fooforandroid\R.java: No such file or directory
[2011-06-01 15:57:58 - ScriptingLayerForAndroid] ERROR: Unable to open class file C:\Android\sl4a\android\ScriptingLayerForAndroid\gen\com\googlecode\android_scripting\R.java: No such file or directory
After much searching I seem to have found the problem. Going into the project properties, Java Build Path, Order and Export, the Android entry was not selected. When selecting it, Eclipse generates the gen directory with R.java in.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletecoud be include more pics to illustrate this steps? :)
ReplyDeleteand today it's recommended to do it as you said? (not attacking, because you did in february... so... could be something change until today...)
thanks
Is there a way to add PHP for Android as a library in this setup?
ReplyDeleteThanks a lot, JohnK! That's fantastic!
ReplyDeleteTested on linux, it work very well. Thank you.
ReplyDeleteone question i installed and all goes fine :)
ReplyDeleteBut i wanted that in a virgin terminal without the sl4a how can i set this as an apk so that the user when installing my application (previously copied from the template and exported) don't need to download python?
You seem to be installing the cloned version of SL4A onto the phone (or emulator) - why? Why not simply use the existing SL4A apk?
ReplyDeleteHi I am almost there but when running build as ants on Copy of ScriptForAndroidtemplate.xml is get the error build failed ....\scriptinglayer\bin not found how does the scriptinglayerabin find its way into ny workspace. Thanks Steve
ReplyDeleteI answered my own question by adding the full path to each line in the build.xml file but is there an easier way.
ReplyDeleteThanks for the detailed instruction. I could convert my python script to apk, transferred it to the phone as well. But after installing and trying to run I get a pop-up 'Python 2.6.2 is not installed. Do you want to download and install APK for Python 2.6.2'. I installed SL4A or Py4A in my emulator and didn't install them on the phone. Is it necessary for me to install Py4A in my phone to run the generated apk?
ReplyDeleteThis is one of the useful script.I like your blog explanation.This is one of the brilliant post.Thanks for your support.
ReplyDeleteAndroid app developers
This comment has been removed by the author.
DeleteThank you for the great post! It is very good for a beginner like me, but I have a question:
ReplyDeleteIs posible to add an automatic installation of python interpreter when installing my app?? The need of installing python could be a problem for a user who knows nothing about programming languages.
Hello JohnK!
ReplyDeleteThank you for this post, but I have a little problem getting over this step:
"Now click Project/Build Automatically, then Project/Clean/Clean all Projects/OK. If you get error messages of files missing try Project/Build All without cleaning first. If you still have errors check if any projects have .jar entries in their libs folders which have not yet been added to the build path (right click/BuildPath/add to Build Path if not - but don't put in duplicate entries). Then try Project/Clean/Clean all Projects/OK (and maybe once more if you still have errors). Ignore the numerous warnings."
Actually, my problem is when I try to "Build All", that option is unavailable to me. Also, I don't have any .jar entries or a "libs" folder.. Also, where should i right click -> buld path/add to build path?
This step is a bit ambiguous.. could you please explain a little better? Or maybe provide a few images?
Thanks a lot in advance!
Nevermind, I managed :) I changed the name of the "project.properties" file into "default.properties", right clicked the project and then selected Android Tools -> Fix Project Properties, cleaned and rebuilded.
ReplyDeleteThough, I have a bit of a question.. can't you run a simple apk without installing Python on the emulator?
ReplyDeleteFor the past few hours I have been struggling with this. Everything went fine until the clean/rebuild step- then the errors didn't go away. I had ~65-70 errors just hanging around & lots about a quickaction.jar that couldn't be found.
ReplyDeleteThe solution: Since I already had Eclipse installed, my Java Compiler compliance level was at 1.5. It NEEDS to be at least 1.6 to allow overriding certain abstract functions, as these libraries do. Configurable in Project Properties -> Java Compiler -> Configure Workspace Settings... -> Compiler compliance level.
I still get this error "The container 'Android Dependencies' references non existing library 'D:\SL4A\hg\android\QuickAction\bin\quickaction.jar' . Any solution to this problem ?
DeleteThis blog is very nice. Thank You for the great post!
ReplyDeleteAndroid Application
I would surely give 10 on 10 for such incredible content.
ReplyDeletecheck here
Your articles make complete sense out of each topic.click for info
ReplyDeleteThank you so much for this post! It was incredibly easy to follow.
ReplyDeletewhy this cloning taking too much time???? does this takes this much time or is it because my internet connection???
ReplyDeleteI would simply say to you all “awesome information”
ReplyDeletehow to root Samsung Galaxy S4 for free
How to add new Facade APIs to SL4A ?. I have downloaded SL4A source, compiled and built it in eclipse after adding two hiddent APIs from BluetoothDevice class ( ie, setpin and setpinconfirmation APIs).
ReplyDeleteI have wrapped these APIs to add those to SL4A apk. Is this the right way to do ?. Do i have to change anywhereelse ?. BTW, after installing this apk, the new SL4A apk crashes. Any clue ?
This is awesome. It lets you experiment with different scripts and it leaves you from all the android sdk compiling work.
ReplyDeleteNice blog. I had 65 errors in quickaction.jar file and i couldn't find. please help.
ReplyDeleteregards
How to make android app
Are u try to the christmas laser light ? click here for Top laser light for christmas
ReplyDeleteThanks for your Great information.
ReplyDeleteCRM software development company in Chennai
That’s a great blog.
ReplyDeleteFor VoIP Dialers, WebRTC development, Digital Marketing and Social Media just try visiting our site!
Digital Communications Specialist
Our Main Services>Web Based Chat
Hearty thanks for this wonderfull information !!!
ReplyDeleteXovoltib 20mg Dose @ Myapplepharmaceuticals
Really amazing !!!
ReplyDeleteAlecensa 150mg @ Myapplepharmaceuticals
Your informations are really helpfull to us !!!
ReplyDeleteScapho 150mg @ Myapplepharmaceuticals
This is really a very good blog post and thanks for sharing
ReplyDeletetrastuzumab,xbira 250mg,
abirapro 250mg,abirapro 500mg
i can set happening my subsidiary concept from this make known. It offers in intensity opinion. thank you for this necessary endorse for all,.. appcloner
ReplyDeletenice
ReplyDeleteI loved your article!! It has given me plenty to think about moving forward on my social media journey!
ReplyDeletePUBG PC Crack
ReplyDeleteSharetipsinfo is investment and trading solutions company is leading Share Market Tips company. Sharetipsinfo provides all types of online stock trading includes best investment tips to their customers. Sharetipsinfo share trading have best Stock Market Tips for investors, equity shares, stock shares and many types of investments in share markets.
aşk kitapları
ReplyDeleteyoutube abone satın al
cami avizesi
cami avizeleri
avize cami
no deposit bonus forex 2021
takipçi satın al
takipçi satın al
takipçi satın al
takipcialdim.com/tiktok-takipci-satin-al/
instagram beğeni satın al
instagram beğeni satın al
btcturk
tiktok izlenme satın al
sms onay
youtube izlenme satın al
no deposit bonus forex 2021
tiktok jeton hilesi
tiktok beğeni satın al
binance
takipçi satın al
uc satın al
sms onay
sms onay
tiktok takipçi satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
instagram beğeni satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
takipcialdim.com/instagram-begeni-satin-al/
perde modelleri
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
betboo
marsbahis
sultanbet
ucuz takipçi
ReplyDeleteucuz takipçi
tiktok izlenme satın al
binance güvenilir mi
okex güvenilir mi
paribu güvenilir mi
bitexen güvenilir mi
coinbase güvenilir mi
thanks Hacklink
ReplyDeleteHacklink
Hacklink
Hacklink
Hacklink
Hacklink
Hacklink
SEO Fiyatları
Vezir Sosyal Medya
kozluk
ReplyDeletegöle
çınarcık
kadirli
safranbolu
gölkaya
aydıntepe
başyayla
dörtyol
erçiş
ReplyDeletebaşkale
sorgun
ereğli
çaycuma
ortaköy
yahşihan
silopi
idil
akçaabat
ReplyDeletearaklı
pertek
akçakale
eyyübiye
siverek
örenşehir
banaz
eşme
kurtalan
ReplyDeleteboyabat
şarkışla
çorlu
çerkezköy
kapaklı
malkara
erbağ
turhal
battalgazi
ReplyDeleteyeşilyurt
alaşehir
soma
alaşehir
turgutlu
şehzadeler
salihli
elbistan
gerede
ReplyDeletemudurnu
bucak
gölhisar
osmangazi
yıldırım
nilüfer
inegöl
gemlik
mudanya
ReplyDeletemustafakemalpaşa
orhangazi
karacabey
iznik
biga
gelibolu
bayramiç
çan
meram
ReplyDeleteereğli
akşehir
beyşehir
seydişehir
karapınar
tavşanlı
simav
gediz
seferihisar
ReplyDeletegüzelbahçe
taşkapı
inebolu
tosya
kocasinan
talas
lüleburgaz
babaeski
çeşme
ReplyDeleteödemiş
kemalpaşa
bergama
menderes
aliağa
tire
balçova
narlıdere
nevşehir
ReplyDeleteniğde
ordu
osmaniye
rize
sakarya
samsun
siirt
sinop
sivas
This comment has been removed by the author.
ReplyDelete