Skip to main content

97 posts tagged with "python"

View All Tags

· One min read

在做講解投影片時自然而然寫出

import package

public class ${Name} extends Activity{ ... public void onCreate(...){ ... setContentView(${layout}) } }

這樣的 python Template 表示法,抽象化有時確實有助於理解。

· 2 min read

Android Scripting Environment (ASE) is the scripting language (BeanShell, Python, Lua, Ruby) environment for Android Operating System.

This article is about how to compile python for ASE.

The following instructions are according to the discussion from ASE group.

Compile python for host To compile python for ASE, you need a Linux machine, then here goes:

Download proper python source distribution (according to the python version in ase/python/src) from http://www.python.org/

Extract the source and run the following command:

$ cd Python-2.6.2 $ ./configure $ make Then you have a clean python compiled for your PC (called host system).

Compile python for target Now we can go to compile python for your Android device (called target system).

Copy the python executable file and the pgen file into ase/python/src folder

$ cd ~ $ cp Python-2.6.2/python ase/python/src/hostpython $ cp Python-2.6.2/Parser/pgen ase/python/src/Parser/hostpgen Then we should prepare the compile tools.

First checkout the android source from http://source.android.com/ (name as mydroid), we'll use the cross compile gcc in it's "prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin" folder. Another tool is located in "ase/tools/agcc".

Edit .bashrc , add a line to include those compile tools:

export PATH=${PATH}:~/mydroid/prebuilt/linux -x86/toolchain/arm-eabi-4.2.1/bin:~/ase/tools/agcc Then start compile python for ASE.

$ cd ase/python $ ./build.py

Done!

· 2 min read

Android Scripting Environment (ASE) is the scripting language (BeanShell, Python, Lua, Ruby) environment for Android Operating System.

The following instructions are according to the discussion from ASE group.

Prerequisites **To compile ASE, you need a Linux machine, then here goes:

1. Get Android source (read http://source.android.com/download to fetch the source) and name the folder as 'mydroid'(or else you prefer). In the following instructions I assume all the folders are in user's home folder(~) .

2. Get Android SDK (download from http://developer.android.com/) and extract it as "android_sdk"(or else you prefer).

3. Get Android Scripting Environment source (hg clone from http://code.google.com/p/android-scripting/source/) as "ase"(or else you prefer).

4. Enter ase/tools folder and execute "fix_android_sdk.py" to patch the "android_sdk".

$ cd ase/tools $ python fix_android_sdk.py ~/mydroid ~/android_sdk Copying source from .....mydroid to .....android_sdk/platforms/android-[verison]/sources Adding android.os.Exec to android.jar Compiling android.os.Exec to.... Done!

In addition to modifying the SDK by adding android.os.Exec, the script will also copy the source files into the SDK so that they can be browsed in Eclipse.

Import Project into Eclipse

After executing the script, follow the instructions for developing in Eclipse in the Android developer guide to setup a workable Android development environment.

Change the project build path and specify the BeanShell path to (project path)/beanshell/bsh-[version].jar Compile it, done!

PS: Python and Lua are precompiled and already put in res/raw folder. You don't need to setup the cross compile environment unless you want to also compile Lua and Python yourself.