Currently, the preferred way to share small scripts with others is via barcode. The easiest way to generate a barcode is to use the ZXing project's online QR Code Generator.
- Open the Contents drop down and choose Text.
- On the first line of the Text Content, enter the name of the script (e.g. hello_world.py).
- Below that, paste the script content.
- Open the Size drop down and choose L.
- Click Generate.
- Embed or share the resulting barcode image with your friends.
To download the script to your phone:
- Launch SL4A or return the scripts list.
- Press the Menu button.
- Tap Add.
- Tap Scan Barcode.
- Scan the barcode and SL4A will add the script to your list.
A QR code can encode 4,296 characters of content. So, this is only effective for small scripts.
Scripts as APKs
There are several ways to publish your script as an APK. The following steps describe how to do that using Eclipse IDE.
- Download script template project archive.
- Import the template project into Eclipse: File > Import > Existing Projects into Workspace, click on Select archive file and fill in the path to your copy of script_for_android_template.zip.
- Set the ANDROID_SDK variable, as described in the compilation instructions.
- Build the project. If Eclipse complains that gen folder is missing and/or there are build path errors, Clean/Build/Refresh should solve the problem.
- Rename the project and the default package com.dummy.fooforandroid -> your_package_name (we suggest using Refactor > Rename). It is important that this is unique because Android system uses package name as an identifier of your APK.
- Update the package property in AndroidManifest.xml package="your_package_name".
- Replace the script.py in res > raw with your script. You can either use the default name script.your_extension or you can name it however you like, in which case make sure to change R.raw.script (Script.java:10) to R.raw.your_script_name.
- Place any additional files (ie, html) into 'res > raw' with your script. They'll be unpacked into the same scripts folder.
- In AndroidManifest.xml uncomment all the permissions that are required to execute your script.
- Create and sign an APK using ADT Export Wizard as described in the Android's Dev Guide.
The following steps describe how to build an APK using Ant.
- Download script template project archive.
- Open a command-line and extract the archive: unzip -d <path/project_directory> script_for_android_template.zip.
- Set the ANDROID_SDK variable to point to the root of your Android SDK directory: export ANDROID_SDK=<SDK_root>.
- Navigate to the root directory of your project and configure your package name: sh configure_package.sh <your_fully_qualified_package_name> (sh configure_package.sh com.dummy.fooforandroid by default).
- Rename the project name in build.xml.
- Replace the script.py in res > raw with your script. You can either use the default name script.your_extension or you can name it however you like, in which case make sure to change R.raw.script (Script.java:10) to R.raw.your_script_name.
- Place any additional files (ie, html) into 'res > raw' with your script. They'll be unpacked into the same scripts folder.
- In AndroidManifest.xml uncomment all the permissions that are required to execute your script.
- Follow Android's Dev Guide to build and sign your application.
For a really detailed walk through, see John K's Blog.
Updating your Template to the latest libraries
Sl4a is being continually updated, whereas your standalone script will be using a static snapshot of whenever you created your copy from the template.
To get the latest version of the template, open script_for_android_template.zip and extract:
libs/script.jar
libs/armeabi/libcom_googlecode_android_scripting_Exec.so
into your project.
If using eclipse, remember to refresh and clean your project.
NB: libcom_googlecode_android_scripting_Exec.so has only been updated once so far, whereas script.jar is being constantly updated.
If you have a full version of the SL4A source installed, and wish to make your own version of script.jar etc, run build.xml in ScriptForAndroidTemplate as a Ant Build.