Monday, October 31, 2011

Building PHP from Scratch

This post by Rahul Amaram describes how to build PHP for Android from scratch and how it can later be used within PAW.
I've added links to the needed files at the end of the post.

Thanks to Rahul for putting this together!

Here is Rahul's documentation...

It is suggested to use a VM for compilation so that you can take snapshots at regular intervals. Also as per google recommendation, it is suggested to use a VM with at least 8 GB RAM/swap and 12 GB of free hard disk.

Install Ubuntu 10.04 64-bit (select username as "joschi") on a VM.

After booting ubuntu, login as joschi.

Download and extract android-php

$ cd
$ wget -c ""
$ sudo apt-get install unzip
$ unzip

First initialize build environment. For donut, java 5 is needed. Also compiling with gcc/g++ 4.4 was throwing errors during compilation. Therefore we use gcc/g++ 4.3 for compilation.

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository "deb hardy main multiverse"
$ sudo add-apt-repository "deb hardy-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \

$ sudo apt-get install g++-4.3-multilib

Download Android source
This will be about 3 GB.

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl > ~/bin/repo
$ chmod a+x ~/bin/repo

$ mkdir ~/android-donut-src
$ cd ~/android-donut-src
$ repo init -u -b android-1.6_r2
$ repo sync

It is a good idea to take snapshot of the VM here.

Build Android

$ cd /usr/bin
$ sudo ln -sf cpp-4.3 cpp
$ sudo ln -sf g++-4.3 g++
$ sudo ln -sf gcc-4.3 gcc
$ sudo ln -sf gcov-4.3 gcov
$ sudo ln -sf cpp-4.3 x86_64-linux-gnu-cpp
$ sudo ln -sf g++-4.3 x86_64-linux-gnu-g++
$ sudo ln -sf gcc-4.3 x86_64-linux-gnu-gcc

$ cd ~/android-donut-src
$ source build/
$ lunch generic-eng
$ make -j4

It is a good idea to take another snapshot of the VM here.

Next build android-php. The patch is applied in order to avoid the error "undefined reference to `__sync_fetch_and_add_4'" during compilation.

$ cd ~/android-php
$ rm -rf ~/android-donut-src/bionic/libc/include/
$ unzip -d ~/android-donut-src/bionic/libc/
$ patch php-5.3.6/ext/standard/php_crypt_r.c < ~/sync_fetch_and_add.patch
$ ./

Finally copy php-5.3.6/sapi/cgi/php-cgi to /mnt/sdcard/paw/html/app/plugins/php_plugin/bin/ on your android phone (be sure to backup the existing php-cgi file), and install PHP using the PAW Web App.



Wednesday, October 19, 2011

Setting up a Cloud Print Printer using the Cloud-X API

The Cloud-X Java API makes it easy to set up a Google Cloud Print aware printer. In the latest API version Cloud Print push notifications are supported.

The below sample code shows the registration of a new printer (if not already present) and how to listen to push notifications.
For the sake of simplicity this is straight forward code, so there might be cleaner ways to do is ;)

Here is the sample code with comments:

  * Process print job
 public static void processJobs(CloudPrintConnection gcp, Printer printer) {
  try {
   List<Job> jobs = gcp.fetch(printer);
   if (jobs != null) {
    for (Job job : jobs) {
     System.out.println("Processing job " + job.getId() + " ("
       + job.getTitle() + ")");
  } catch (Exception e) {

 public static void main(String[] args) {
  try {
   String printProxy = "testprinter-" + NetworkUtil.getMacAddress();

    * Our printer
   final Printer printer = new Printer();
   printer.setName("Test Printer");

   final CloudPrintConnection gcp = new CloudPrintConnection();
   gcp.connect(username, password, "cloudprint",
     "Cloud Print Test Client", null);

    * Register printer if not already present
   List<Printer> printers = gcp.list(printProxy);
   if (printers.size() == 0) {
    System.out.println("Registering Printer with Proxy "
      + printProxy);
    gcp.register(printer, null);
   } else {

    * Refetch all printer info

   System.out.println("Printer Name: " + printer.getName());
   System.out.println("Printer ID: " + printer.getId());

   processJobs(gcp, printer);

    * Wait for push notifications
   PushReceiver pr = new PushReceiver("Cloud-X API - Push Receiver");
   pr.addListener(new PushListener() {

    public void onReceive(String printerId) {
     if (printerId.equals(printer.getId())) {
      processJobs(gcp, printer);

    public void onConnect() {
      System.out.println("Connected to Google Talk!");

    public void onDisconnect() {
      // Do nothing

   pr.connectPlain(username, password);

  } catch (Exception e) {


Thursday, October 13, 2011

Cloud-X - Sharing Files through the Cloud

We just released the first alpha version of Cloud-X.
Cloud-X uses Google Cloud Print to share files between different users and devices. Along with the PC and Android app the Java API to access Google Cloud Print is also released.

This is a very early version, so there might be bugs.
The Android app and an online and stand alone PC version can be found at the following site:

Comments welcome!


The website is no longer online.
API with included sources can be downloaded from