Question 1. What Is Scripting Layer For Android (sl4a) For?
SL4A makes it possible to quickly prototype applications for Android on the device itself using high-level scripting languages. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface.
Question 2. Why Sl4a? Android Programs Are Easy Enough To Write.?
That’s very true. Android’s development environment does make life pretty easy. But, you’re tied to a computer to do your work. SL4A lets you try out an idea now, in the situation where you need it, quickly.
Question 3. How Does Sl4a Work?
SL4A provides Android facades which make APIs available via JSON RPC calls. Only the parts of Android’s APIs which has been wrapped by facades are available to interpreters.
Question 4. Does Sl4a Compile The Supported Languages To Dex Bytecode Or Is There An Additional Layer Of Interpretation?
It depends on the language a bit. BeanShell is run in the JVM and has an additional layer of interpretation. Lua, Python, and Perl are actually the C versions running natively.
All interaction with Android is over RPC channels. Still, the RPC API is compiled to dex so there’s no additional interpretation in Java (other than reflection).
Question 5. What About Performance?
With respect to the interpreters SL4A provides, Lua and Python are both cross compiled C binaries that run in their own process. CPython is significantly more performant than Jython (especially since Android does not currently support JIT).
As for the Android facades, the API is primarily focused on making it easier to write scripts than on the performance of those scripts. That said, remember the adage “measure first, then optimize.” SL4A is about rapid development after all.
If you have performance concerns for your application, it’s probably better to use the standard Android SDK (or NDK) where you’ll have more control over the system.
Question 6. Are Scripts First-class Apps From The Point Of View Of The System?
Yes, mostly. You can invoke arbitrary intents and there are also plans to support broadcast receiver scripts. That is, you could write an app that consumes photos and shows up in the list of apps when the user presses Share in the Camera app.
It is not currently possible to write a script that will exit with a result (e.g. another Android activity starts your activity for result).
Question 7. Is This A Complete Api Bridge, Or Are There Restrictions?
BeanShell, JRuby, and Rhino basically give you a complete API bridge (you can invoke Java calls directly). See the documentation for those interpreters for instruction on how to accomplish this. Cross compiled languages like Lua are more restricted. They only have access to the APIs exposed through the RPC layer.
Question 8. What Do I Do With All These Barcodes?
Barcodes are a easy way to access a web link on your phone (e.g. to download SL4A).
Question 9. Where Are The Sample Scripts And Other Interpreters?
As of release 0.8 alpha, interpreters and sample scripts are distributed separately. Please read InstallingInterpreters for directions on how to add them.
Question 10. Can I Run Scripts As Root?
If you have a rooted phone, you may be interested in doing so. At the moment, SL4A does not support this directly.
Question 11. How Do I Install Sl4a?
- Enable “Unknown Sources” under Application settings.
- Install Barcode Scanner.
- Scan the barcode on the home page to download the APK.
- Tap on the downloaded APK to install SL4A.
Question 12. Can I Use Sl4a To Write A Real Android Application Or Embed Sl4a Scripts In My Application?
Yes! You can embed your script in a (mostly) stand alone APK.
Question 13. Will Sl4a Work On An Android Emulator?
Yes. Use adb install sl4a_rnn.apk to install it to the emulator.
Question 14. Will Sl4a Work On My Android Device That’s Not Built On Arm (e.g. X86)?
Yes and no. All cross compiled interpreters are compiled for ARM. Java based interpreters like JRuby, BeanShell, and Rhino will work.
Question 15. Can I Run An Sl4a Script From My Application?
Yes. See IntentBuilders.java.
Question 16. My Script Stops Working When The Screen Turns Off! Wtf?
Your phone turns the screen off, among other things, when it goes to sleep. If an application doesn’t request that it keep running when the phone is asleep, it will stop running until the phone wakes up again (i.e. you turn the screen back on). Requesting that the device remain on while your application is running is called a wake lock.
SL4A provides APIs for acquiring and releasing wake locks. It is important to note that wake locks significantly impact battery life. You should always release a wake lock as soon as possible.
Instead of using a wake lock, you can also enable the “Stay awake” system setting. From your home screen tap Menu, Applications, Development, and check Stay awake. With that enabled, your phone will never sleep while charging. This does affect the amount of time it takes to charge your phone, however.
Question 17. Can I Use Sl4a For Ui Automation?
No. For security reasons, it is only possible for the shell user to inject UI events into arbitrary applications. See UI/Application Excersier in the Android documentation.
Question 18. What Usage Information Does Sl4a Collect?
If you enable “Usage Tracking”, the application will collect anonymous usage information through Google Analytics.
Question 20. Where’s Php?
There is a PHP interpreter, which is a separate project. The PHP installer and interpreter can be found there.
Question 21. What’s Logcat?
Logcat is a rotating log of messages that Android produces. It’s a very useful tool for programmers to work out what exactly is going on if someone reports and error. It’s a requirement in our Issues reporting to attach a logcat wherever possible.
Question 22. Sl4a Won’t Install Interpreters On An Emulator?
In fact, SL4A works fine on emulators, having been to a large degree developed on them. But these interpreters require a bit of room, and the default AVD size for a sdcard is on 16Mb. This is inadequate. I would allocate a minimum of 128Mb, and in fact commonly set mine to 512Mb. Bear in mind that it’s unusual to get an Android device with less than 2Gb these days.
Perl Scripting Interview Questions
Perl Scripting Tutorial
Python Interview Questions
IBM-REXX Interview Questions
Ruby Interview Questions
Perl Scripting Interview Questions
Java Bean Utils Interview Questions
Ruby on Rails 2.1 Tutorial
Rhinoceros 3D Interview Questions
Python Interview Questions
Java Bean Utils Tutorial
wxPython Interview Questions