You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by "Cliff Jansen (JIRA)" <ji...@apache.org> on 2013/04/18 19:25:16 UTC

[jira] [Created] (PROTON-298) proton-c on Android

Cliff Jansen created PROTON-298:
-----------------------------------

             Summary: proton-c on Android
                 Key: PROTON-298
                 URL: https://issues.apache.org/jira/browse/PROTON-298
             Project: Qpid Proton
          Issue Type: Wish
          Components: proton-c
    Affects Versions: 0.5
         Environment: Android + swig + proton-c
            Reporter: Cliff Jansen
            Assignee: Cliff Jansen
            Priority: Trivial


Here are notes on getting proton-c to work on Android in case it is of use or provides insight from the mobile environment.  I may try iOS next, but first I need access to a development box and pay the Apple developer fee.  Since I could try Android with spare parts at hand, it goes first and is the subject of this JIRA.

Aside from fudging a build, the actual C portability issues boiled down to:

  no uuid, opennsl support.
  Missing getprotobyname().

What I did:

 - download the Android NDK and SDK for Linux
 - confirm installed Java and ant were appropriate
 - started with the Swig and Android C example (http://www.swig.org/Doc2.0/Android.html)
 - update the swig example to mimic the proton recv.c example using JNI to qpid-proton

I opted to run without eclipse.  Once I could build and run the swig example app, I looked at the resulting project and weighed the pros and cons of calling cmake from ant or vice versa.

In the end I cheated, just to get something to work.  I reasoned that the Android build should closely approximate a Linux build so I merely did two builds and synced things by hand from the Linux build to the Android one.  Ignoring the blind alleys I walked down, here is the basic process:

Download trunk and do a normal Linux cmake, "make VERBOSE=1" (and save the output).

Elsewhere, create a new Android project:

  android create project --target 1 --name PnTest --path ./pntest --activity PnTest --package org.apache.qpid.pnswig

This creates the stub tree to build from.  Now update and populate, put the proton trunk in the appropriate "jni" directory, copy generated files from the linux build.

  mkdir pntest/jni
  (cd pntest/jni; tar xf /path/to/pn.1467710.tar && mv trunk pn)
  mkdir -p pntest/jni/pn/bld_copy/proton-c
  cp /path/to/linux/trunk/build/proton-c/*.h pntest/jni/pn/bld_copy/proton-c

Use the same swig command from the Linux build adjusted for the changed include directory names

  mkdir -p pntest/src/org/apache/qpid/proton/jni
  /usr/bin/swig -java -package org.apache.qpid.proton.jni -outdir pntest/src/org/apache/qpid/proton/jni -I/b/xtra/drd/cj/pntest/pntest/jni/pn/bld_copy/proton-c -I/b/xtra/drd/cj/pntest/pntest/jni/pn/proton-c/include -o javaJAVA_wrap.c /b/xtra/drd/cj/pntest/pntest/jni/pn/proton-c/bindings/java/java.i
  mv javaJAVA_wrap.c pntest/jni/javaJAVA_wrap.c

After this, the steps are the same as the basic swig example program.

  update AndroidManifest.xml for minSdkVersion and android.permission.INTERNET
  update the main source file and resources to use proton
  create an Android.mk based on Linux builds for qpid-proton
  update pntest/jni/pn/proton-c/src/posix/driver.c for API problem:
    getprotobyname("tcp")->p_proto is not supported, use "IPPROTO_TCP"

Build it

  (cd pntest; ndk-build)
  (cd pntest; ant debug)

Install on your device and play :-)

The getprotobyname outage was surprisingly found at runtime (in the system log), it linked fine.  The openssl outage was found at compile time.

In Android.mk, the choice of flags (-DUSE_CLOCK_GETTIME -DUSE_UUID_GENERATE -DUSE_STRERROR_R -DUSE_ATOLL -std=gnu99) were stolen from the Linux cmake build output.  The uuid_hack portion just pulls in a linux implementation; I won't discuss that except to say that a little searching can point you to a less ugly way to do it.  Similarly, people are rolling their own openssl support.

Also, people are using cmake to cross compile Android binaries, so there is surely a much cleaner way to build libqpid-proton.so and the swig bits and just drop them into the Android project.


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira