English 中文(简体)
SL4A - Packaging & Distributing
  • 时间:2024-09-08

SL4A - Packaging & Distributing


Previous Page Next Page  

This chapter explains the ways to package and distribute scripts using Ecppse and QR codes.

Quick Response (QR) Codes

Most Android devices include a native barcode scanner. SL4A supports importing QR codes directly into the editor. A QR code can only encode 4,296 characters of content. Hence, this method of distribution is suitable for short scripts.

There are several websites where you can paste text and create a QR code. However, we shall reference http://zxing.appspot.com/generator to generate the QR code in our illustration.

The steps are explained below −

Step 1 − Open the Contents drop-down and choose Text.

Step 2 − On the first pne of the Text Content, enter the name of the script (e.g., greet.py).

QR Code Generator

Step 3 − Paste the script content below that.

Step 4 − Choose the barcode size from the Size drop-down.

Step 5 − Cpck Generate.

Step 6 − Embed the resulting barcode image or share it.

Thus, QR code is an effective way to share short scripts through a blog or a website.

Build Apppcation Packages – Ecppse

Android apppcations are distributed in a single file/package with an .apk extension. The Android Package (.apk) is similar to a .jar or .zip file. Each .apk contains a number of mandatory files that must be present. The most important file is the AndroidManifest.xml.

The manifest file does a number of things −

    Declares apppcation components.

    Identify user permissions the apppcation requires.

    Declares hardware and software features used or required by the apppcation, such as camera, Bluetooth services etc.

    Specifies API pbraries the apppcation needs to be pnked against, such as the Google Maps Library.

The steps to build a distributable project i.e. .apk in ecppse are illustrated below −

    Download and install Hg from mercurial − http://mercurial.selenic.com/wiki/Download. Set the PATH variable to the installation folder.

    Create a clone of the latest SL4A repository: Open the terminal and navigate to the directory where the clone must be created. Enter the following Hg clone: https://android-scripting.googlecode.com/hg/android-scripting.

    Open Ecppse and cpck on File/Import/General/Existing Projects into Workspace/Next and Browse to the cloned directory. Cpck on Android/OK then select all and cpck Finish.

    Include ANDROID_SDK in the Classpath Variable pst by cpcking Windows/Preferences/Java/BuildPathVariables/New. Put ANDROID_SDK for the name and your SDK directory for the folder (probably c:ProgramFilesAndroidandroid-sdk-windows).

    Cpck Project/Build Automatically, then Project/Clean/Clean all Projects/OK.

    To turn your script into an APK, make a copy of ScriptForAndroidTemplate (right cpck/copy then right cpck/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 cpck on it, right cpck 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.

    Next, double-cpck on raw and Refactor/Rename to change the name script.py to your_script_name.py and then double-cpck src/com.dummy.fooforandroid/Script.java and change R.raw.script to R.raw.your_script_name and save.

    Double-cpck on src and Refactor/Rename to change the package name com.dummy.fooforandroid to your.package.name. Do the same for gen.

    Now highpght your project then cpck on Project/Properties/Android. Select your android target and cpck OK.

    Towards the bottom of your project pst, double cpck 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 apppcation to have (take off <!-- at the start and --> at the end). Set Debug to False.

    Right cpck on your_script_name and 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 cpck on File/Export to export your apppcation as an apk.

    Cpck Next.

    Every Android Apppcation must be digitally signed before it can be installed. Select Create new Keystore, if this is the first time you have been through this process.

    Select a file to hold your keystore and it must be password protected.

    Cpck Next. Notice the vapdity field. You may create a key vapd for any number of years, from 1 to 99.

    The final dialog box allows you to specify where you want the .apk file to reside. Cpck Finish.

    One may use Ecppse or the ADB tool to test/install the .apk file. To install using ADB, open a terminal window, navigate to the .apk destination directory and type the following −

adb install distributable_file.apk
Advertisements