Scripting Layer for Android (SL4A) brings scripting languages to Android byallowing you to edit and execute scripts and interactive interpreters directlyon the Android device. These scripts have access to many of the APIs availableto full-fledged Android applications, but with a greatly simplified interfacethat makes it easy to get things done.
Scripts can be run interactively in a terminal, in the background. Python,Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported,and we're planning to add more. See the SL4A Video Helpplaylist onYouTube for various demonstrations of SL4A's features.
SL4A is designed for developers and is alpha quality software.Please report bugs and feature requests on the issues list.
You can download the current APK by scanning or clicking the following barcode:
SL4A makes it possible to quickly prototype applications for Android on the device itself using high-level scripting languages. SL4A provides Android facades which make the Android APIs available via JSON RPC calls. As for the Android facades, the API is primarily focused on making it easier to write scripts than on the performance of. This is possible using SL4A's 'server' support. To use remote control with your USB connected Android smartphone, you first have to install the USB Driver for your Android Smartphone. Start an SL4A server from the Interpreter Manager. (From the SL4A frontpage, press Menu, then Interpreters, then Menu, then Start Server). Start a private server.
The original Google Code wiki has been converted to Markdown andis available in the docs folder.A few of the most important pages are:
I ignored the issues in google-code, because it's not controllable.New issues will be accepted from issue page. /download-game-crash-of-cars-mod-apk-offline.html.
To install SL4A, you will need to enable the 'Unknown sources' option inyour device's 'Application' settings.
Still have questions? Check out the FAQ.
Support for SL4A is provided by the community on the project mailinglist.
Start by reading 'Introducing SL4A: The Scripting Layer for Android'by Pieter Greyling and 'Packaging and Distributing'by Paul Ferrill.
These are the intellectual property of Apress and are excerpt from the books'Practical Android Projects' and 'Pro Android Python with SL4A.'
You can buy 'Practical Android Projects' onAmazonor directly from Apress.
Apress is happy to provide 25% off the price of the'Practical Android Projects' eBook.Simply enter the special code 'SL4APROJECTROCKSHLDD' upon checkout whenpurchasing the eBook here.Offer expires 12/30/11.
You can buy 'Pro Android Python with SL4A' directly fromApress.
Apress is also happy to provide 25% off the price of the 'Pro Android Pythonwith SL4A' eBook.Simply enter the special code 'THESL4APROJECTROCKS' upon checkout whenpurchasing the eBook here.Offer expires 12/30/11.
Want to see SL4A in action? Check out some of these cool SL4A powered projects:
SL4A was used by the Nexus One payload for sensor logging.See the article in Makefor more information about the project.
We are a collection of hobbyists who want to free your cell phonefrom your pocket and let it connect and move with the real world. How?As a robot of course!
Cellbots aren't just about using your phone to control arobot (which is cool too), but we aim on making your phone be the robot.
It already has touch, hearing, speech, vibration, and many more senses,but needs legs (or wheels) to finally be the free roaming robot it wasborn to be.
See the Cellbots blog orYouTube channel for more.
Using a single master password and various account names,one can create an infinite number of unique account passwords.
These unique account passwords are commonly called password hashes,domain-specific passwords, or per-site passwords.
See the Oplop project pagefor more information.
Broadcast is an embedded web application for remote Android device management.Broadcast has four goals:
See the project homepage, thispresentation,and this screenshot for more information.
SMS Merger is an excellent example of what can be done with Python andthe WebView API.SMS Merger is designed to send a series of personalized SMS. For example,to let Antony, Bob and Claire know which seat number they have beenallocated for their exams, SMS Merger can turn a CSV file intothe following SMS messages:
See thesescreenshotsand Frank's blog for more information.
Have a project you'd like to see listed here? Tell us about it on themailing list.
Please replace /path/to strings to your environment or installed place.
After Android Studio launch,
Clone this project, and import it into Eclipse. Make sure that the Java compliancelevel is at 1.6 (right-click any project, go to Properties > Java Compiler > Configure Workspace Settingsand select 1.6.
Make sure that you have all the appropriate Android SDKs installed through Eclipse. You can determinethis by looking at what errors prop up.
Make sure the environment variable ANDROID_SDK is set, by going to Window > Preferences > Java >Build Path > Classpath Variables and creating a new variable ANDROID_SDK that points to the android-sdksfolder.
Make sure you clean all projects by going to Project > Clean.
If there are still issues, look at this to find tidbits you could possibly do:http://jokar-johnk.blogspot.co.nz/2011/02/how-to-make-android-app-with-sl4a.html
Languages are shipped with Android application. (but not maintainanced well except of python.)
The Scripting Layer for Android, SL4A, is an open source application that allows programs written in a range of interpreted languages to run on Android. It also provides a high level API that allows these programs to interact with the Android device, making it easy to do stuff like accessing sensor data, sending an SMS, rendering user interfaces and so on.
It's is really easy to install and it works on any stock Android device, so you don't need to be root or anything like that.
Currently, the Scripting Layer supports Python, Perl, Ruby, Lua, BeanShell, JavaScript and Tcl. It also provides access to the Android system shell, which is actually just a minimal Linux shell.
You can find out more about the SL4A project from their website.
There are a couple of other options for running Python on Android, and some are very good, but none offer the flexibility and features of the Scripting Layer. The alternatives really focus on enabling you to create and package a native app using some otherwise unsupported language, and some do that really well. For example, with Kivy, you can create an app in Python that'll run across many popular operating systems, desktop and smartphone, including Android. However because it's multi-platform, you don't have any way of directly accessing the Android API, so you can't use many of the features that make smartphones so interesting.
SL4A was designed around the Android OS: It requires Android to be useful, but allows much closer integration with the operating system.
With SL4A, you can still package your apps, and you can publish them to app stores like Play if you like, but it's just an option. One advantage to having packaging as an option, rather than as a purpose, is that most Python scripts, in practice, are not actually published through app stores anyway. They're meant to be used as regular Python programs. You'll normally just want to write a bit of code, save it, then run it, and keep iterating. Having to keep building the app is just tedious.
With the Scripting Layer, you can start hacking away like you would on any other system, just editing and executing files.
This series focuses on Python, and Python is the most popular and well supported language on SL4A, but the other languages have features which can be really useful. For example, BeanShell, which is a very high level language that compiles to Java, has the ability to side-step the Scripting Layer API and access the Android Java API directly. The Scripting Layer's Ruby and JavaScript interpreters, JRuby and Rhino, also run on the JVM, so these languages can do this too. It's nice to have an environment with these kinds of features available.
SL4A is really easy to install. The application is distributed as an APK, the standard format for Android apps, so it can be installed in the same way. However, before installing apps from 'unknown sources', you need to allow that on your device. If you haven't already, open your device's main Settings menu, open the Security menu, then 'allow installation of non-Market apps' by checking the Unknown Sources option. Now you're ready to install the Scripting Layer.
If you go to the SL4A project's home page, you can download a copy of the Scripting Layer APK to your device by just scanning the barcode on that page and confirming the download when prompted. If you don't have a barcode scanner on your device, there's always a bunch of gratis scanners available from any app store.
Once you've downloaded the APK, you should be able to install it from directly within your device's notifications panel, where the download will appear. You device may differ slightly, but it will be obvious how you install the APK, as long as you've enabled installation from unknown sources.
Once you've installed the Scripting Layer, you'll be able to open it, create and edit little shell scripts with the built-in editor and run them. It very easy to get started.
Whenever you first open SL4A, you'll see the contents of your scripts directory, which lives at /sdcard/sl4a/scripts
. This is where you'll normally put your own scripts for easy access. You can create directories in here to help keep things sane if you want to build more complex applications, or just to organise simple scripts if you have a lot of them.
SL4A only includes the shell as standard, but installing other interpreters is easy to do from within the app. If you open SL4A, then hit your devices main menu button, and the SL4A menu will pop up. If you press View, you'll see a menu with three options, Interpreters, Triggers and Logcat. Selecting Interpreters will move your view from the scripts directory to the interpreters list. Hitting the device's main menu button in this view will open a new menu with an option to add interpreters. From here you can select which interpreter you want to install, which will open your browser and download the APK for that interpreter. Install this APK in the same way that you installed SL4A.
Each interpreter exists as a separate Android app and will appear as an app in the device's menus. The Python Interpreter's app is called Python for Android, or just PY4A. Each interpreter's app has, at least, the ability to install or uninstall the interpreter. PY4A can also manage .egg files, which gives you an easy way to install Python C modules on the Scripting Layer, where you can otherwise only use pure Python. Any Python C modules must first be cross-compiled for ARM cores, which is an involved process, but some useful packages are available pre-compiled from the Python for Android project pages, along with instructions on how to compile others.
If you haven't already, open the Python for Android app and hit the Install button. Your Scripting Layer now supports Python.
If you'd like to add new modules to extend the device's Python library, you have to do things a bit differently to what you're probably used to. Without root, you can't directly modify the system files, so the Scripting Layer has its own directory for packages that lives on your sdcard at /sdcard/com.googlecode.pythonforandroid/extras/python
. You can always import from this directory and similar directories exist for each language you have installed.
The Python extras directory comes preloaded with a ton of useful modules, and you can chuck any pure Python modules you like in here.
If you add a module to the extras directory, make sure it's the importable Python module itself. When you grab a library from a repository, it'll normally be structured so that the app's root directory contains a bunch of stuff like READMEs, docs, tests and setup files, as well as the actual module you need, which may be a file or a directory. Remember, it must be pure Python and you will have to resolve any dependencies.
Note: If you don't have a decent file browser on your device, grab one immediately. I normally use ES File Explorer which is free on Play. If you want to get seriously into hacking Androids, it's a good idea to install the Android SDK on a dev box sooner rather than later too. It includes tools that make light work of some common tasks. It's a fairly complex bit of kit, but guides for each OS are readily available online, and you'll need it to package apps.
You have a bunch of example scripts installed automatically in the scripts directory whenever you add a new interpreter. These are a good place to start looking for code examples, and you can safely delete them once you're done.
Using SL4A in Python is really simple. Most scripts start with the following two lines:
2 | droid=Android() |
From here, the name droid
is an Android
object and acts as a hook to the Android device. You use it to access the entire Scripting Layer API. The API is divided into sections called facades, with each facade covering some area of the API, such as Webviews, Phone, WiFi, Events, Camera, Battery and so on.
For example, you can use the text to speech facade to make the droid speak:
Note: Tasker also supports SL4A scripting, so you can use that to monitor the system and launch Python programs whenever certain conditions are met.
The raw API is fully documented, online. However there's very little information about how to use it. There's more information at the SL4A and PY4A project sites, but not nearly enough. Personally, I reckon open source devs are smart enough to know to never write documentation ~ that way, they can earn a living writing books..
The Apress book Pro Android Scripting with SL4A, by Paul Ferrill, really is an awesome resource for learning to use the Scripting Layer properly, and uses Python as the example language. Apress have also published Beginning Android Tablet Programming, by the SL4A project's lead developer, Robbie Matthews. This is more focussed on tablets specifically, and less focussed on Python, but is still an excellent book from someone who really knows their subject.
There's also the SL4A and PY4A Google Groups to look to for help. They can be a bit lonely, but if you word your question well, you'll normally get a helpful reply before very long. There's plenty of archived material there too.
This Python Central Series aims to cover all the most important things Python programmers need to know about Android and the Scripting Layer, to help you get up to speed. And, as always, we'd really appreciate the community's input on our project, so if there's anything you'd like to see, make sure you let us know about it.