I installed everything to compile the spatial object as a shared library, and geos and proj as static libraries (statically linked to spatial space). They also need libiconv (AFAIK), since the NDK libc does not provide iconv.h.
Fortunately, they are all LGPL or compatible, so they can be safely included in the application without fear of license problems.
NOTE. You must first run './configure', inside libiconv and libspatialite, to generate headers. This requires the installation of "autoconf".
Also note that this is on Linux (Ubuntu 10.10).
GEOS cannot be built and linked right now because C ++ support for STL is completely absent in the NDK. If anyone can come up with a solution for building a GEOS, let us know! I'm not sure how important it is to have advanced features in GEOS, but it saves more than 1 MB of library size, leaving it in line with README.
Here is my main 'jni / Android.mk'. It can be divided into several files, but I was not worried because I am lazy :-)
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := iconv LOCAL_CFLAGS := \ -Wno-multichar \ -D_ANDROID \ -DLIBDIR="\"c\"" \ -DBUILDING_LIBICONV \ -DIN_LIBRARY LOCAL_C_INCLUDES := \ libiconv-1.13.1 \ libiconv-1.13.1/include \ libiconv-1.13.1/lib \ libiconv-1.13.1/libcharset/include LOCAL_SRC_FILES := \ libiconv-1.13.1/lib/iconv.c \ libiconv-1.13.1/lib/relocatable.c \ libiconv-1.13.1/libcharset/lib/localcharset.c include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := proj LOCAL_C_INCLUDES := proj-4.7.0/src LOCAL_LDLIBS := -lm
With this, you will need to apply some minor corrections to the sources in order to get things to pull in the correct headers. The Mac build was close, but using -D_APPLE_ caused some other oddities. I ended up just fixing the parts of libiconv and spaceite that I need:
diff --git a/android/jni/libiconv-1.13.1/libcharset/lib/localcharset.cb/android/jni/libiconv-1.13.1/libcharset/lib/localcharset.c index 434fc7c..44b087d 100644 --- a/android/jni/libiconv-1.13.1/libcharset/lib/localcharset.c +++ b/android/jni/libiconv-1.13.1/libcharset/lib/localcharset.c @@ -44,7 +44,7 @@ # endif #endif -#if !defined WIN32_NATIVE +#if !defined(WIN32_NATIVE) && !defined(__ANDROID__) # if HAVE_LANGINFO_CODESET # include <langinfo.h> # else @@ -328,7 +328,7 @@ locale_charset (void) const char *codeset; const char *aliases; -#if !(defined WIN32_NATIVE || defined OS2) +#if !(defined WIN32_NATIVE || defined OS2 || defined __ANDROID__) # if HAVE_LANGINFO_CODESET diff --git a/android/jni/libspatialite-amalgamation-2.3.1/spatialite.cb/android/jni/libspatialite-amalgamation-2.3.1/spatialite.c index 5fed6f0..d482ecc 100644 --- a/android/jni/libspatialite-amalgamation-2.3.1/spatialite.c +++ b/android/jni/libspatialite-amalgamation-2.3.1/spatialite.c @@ -72,7 +72,7 @@ extern const char * locale_charset (void); #include <localcharset.h> #endif /* end localcharset */ #else /* not WINDOWS */ -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__ANDROID__) #include <iconv.h> #include <localcharset.h> #else /* not Mac OsX */ @@ -7508,7 +7508,7 @@ gaiaCleanSqlString (char *value) #define LIBCHARSET_STATIC /* #include <localcharset.h> */ #else /* not MINGW32 - WIN32 */ -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__ANDROID__) /* #include <iconv.h> */ /* #include <localcharset.h> */ #else /* not Mac OsX */ @@ -7526,7 +7526,7 @@ gaiaGetLocaleCharset () #if defined(__MINGW32__) || defined(_WIN32) return locale_charset (); #else /* not MINGW32 - WIN32 */ -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__ANDROID__) return locale_charset (); #else /* not Mac OsX */ return nl_langinfo (CODESET); @@ -13896,7 +13896,7 @@ gaiaPolygonize (gaiaGeomCollPtr geom_org, int force_multipolygon) #define LIBCHARSET_STATIC /* #include <localcharset.h> */ #else /* not MINGW32 */ -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__ANDROID__) /* #include <iconv.h> */ /* #include <localcharset.h> */ #else /* not Mac OsX */
And here is the conclusion:
mark@beast :~/Code/android-spatialite/jni$ ndk-build Compile thumb : spatialite <= spatialite.c Compile thumb : spatialite <= sqlite3.c /home/mark/Code/android-spatialite/jni/./libspatialite-amalgamation-2.3.1/sqlite3.c: In function 'unixDlError': /home/mark/Code/android-spatialite/jni/./libspatialite-amalgamation-2.3.1/sqlite3.c:24986: warning: assignment discards qualifiers from pointer target type Compile thumb : iconv <= iconv.c Compile thumb : iconv <= relocatable.c Compile thumb : iconv <= localcharset.c StaticLibrary : libiconv.a Compile thumb : proj <= aasincos.c Compile thumb : proj <= adjlon.c Compile thumb : proj <= bch2bps.c Compile thumb : proj <= bchgen.c Compile thumb : proj <= biveval.c Compile thumb : proj <= cs2cs.c Compile thumb : proj <= dmstor.c Compile thumb : proj <= emess.c Compile thumb : proj <= gen_cheb.c Compile thumb : proj <= geocent.c Compile thumb : proj <= geod.c Compile thumb : proj <= geod_for.c Compile thumb : proj <= geod_inv.c Compile thumb : proj <= geod_set.c Compile thumb : proj <= jniproj.c Compile thumb : proj <= mk_cheby.c Compile thumb : proj <= nad2bin.c Compile thumb : proj <= nad2nad.c Compile thumb : proj <= nad_cvt.c Compile thumb : proj <= nad_init.c Compile thumb : proj <= nad_intr.c Compile thumb : proj <= PJ_aea.c Compile thumb : proj <= PJ_aeqd.c Compile thumb : proj <= PJ_airy.c Compile thumb : proj <= PJ_aitoff.c Compile thumb : proj <= pj_apply_gridshift.c Compile thumb : proj <= PJ_august.c Compile thumb : proj <= pj_auth.c Compile thumb : proj <= PJ_bacon.c Compile thumb : proj <= PJ_bipc.c Compile thumb : proj <= PJ_boggs.c Compile thumb : proj <= PJ_bonne.c Compile thumb : proj <= PJ_cass.c Compile thumb : proj <= PJ_cc.c Compile thumb : proj <= PJ_cea.c Compile thumb : proj <= PJ_chamb.c Compile thumb : proj <= PJ_collg.c Compile thumb : proj <= PJ_crast.c Compile thumb : proj <= pj_datums.c Compile thumb : proj <= pj_datum_set.c Compile thumb : proj <= PJ_denoy.c Compile thumb : proj <= pj_deriv.c Compile thumb : proj <= PJ_eck1.c Compile thumb : proj <= PJ_eck2.c Compile thumb : proj <= PJ_eck3.c Compile thumb : proj <= PJ_eck4.c Compile thumb : proj <= PJ_eck5.c Compile thumb : proj <= pj_ellps.c Compile thumb : proj <= pj_ell_set.c Compile thumb : proj <= PJ_eqc.c Compile thumb : proj <= PJ_eqdc.c Compile thumb : proj <= pj_errno.c Compile thumb : proj <= pj_factors.c Compile thumb : proj <= PJ_fahey.c Compile thumb : proj <= PJ_fouc_s.c Compile thumb : proj <= pj_fwd.c Compile thumb : proj <= PJ_gall.c Compile thumb : proj <= pj_gauss.c Compile thumb : proj <= pj_geocent.c Compile thumb : proj <= PJ_geos.c Compile thumb : proj <= PJ_gins8.c Compile thumb : proj <= PJ_gnom.c Compile thumb : proj <= PJ_gn_sinu.c Compile thumb : proj <= PJ_goode.c Compile thumb : proj <= pj_gridinfo.c Compile thumb : proj <= pj_gridlist.c Compile thumb : proj <= PJ_gstmerc.c Compile thumb : proj <= PJ_hammer.c Compile thumb : proj <= PJ_hatano.c Compile thumb : proj <= PJ_imw_p.c Compile thumb : proj <= pj_init.c Compile thumb : proj <= pj_initcache.c Compile thumb : proj <= pj_inv.c Compile thumb : proj <= PJ_krovak.c Compile thumb : proj <= PJ_labrd.c Compile thumb : proj <= PJ_laea.c Compile thumb : proj <= PJ_lagrng.c Compile thumb : proj <= PJ_larr.c Compile thumb : proj <= PJ_lask.c Compile thumb : proj <= pj_latlong.c Compile thumb : proj <= PJ_lcca.c Compile thumb : proj <= PJ_lcc.c Compile thumb : proj <= pj_list.c Compile thumb : proj <= PJ_loxim.c Compile thumb : proj <= PJ_lsat.c Compile thumb : proj <= pj_malloc.c Compile thumb : proj <= PJ_mbtfpp.c Compile thumb : proj <= PJ_mbtfpq.c Compile thumb : proj <= PJ_mbt_fps.c Compile thumb : proj <= PJ_merc.c Compile thumb : proj <= PJ_mill.c Compile thumb : proj <= pj_mlfn.c Compile thumb : proj <= PJ_mod_ster.c Compile thumb : proj <= PJ_moll.c Compile thumb : proj <= pj_msfn.c Compile thumb : proj <= pj_mutex.c Compile thumb : proj <= PJ_nell.c Compile thumb : proj <= PJ_nell_h.c Compile thumb : proj <= PJ_nocol.c Compile thumb : proj <= PJ_nsper.c Compile thumb : proj <= PJ_nzmg.c Compile thumb : proj <= PJ_ob_tran.c Compile thumb : proj <= PJ_ocea.c Compile thumb : proj <= PJ_oea.c Compile thumb : proj <= PJ_omerc.c Compile thumb : proj <= pj_open_lib.c Compile thumb : proj <= PJ_ortho.c Compile thumb : proj <= pj_param.c Compile thumb : proj <= pj_phi2.c Compile thumb : proj <= PJ_poly.c Compile thumb : proj <= pj_pr_list.c Compile thumb : proj <= PJ_putp2.c Compile thumb : proj <= PJ_putp3.c Compile thumb : proj <= PJ_putp4p.c Compile thumb : proj <= PJ_putp5.c Compile thumb : proj <= PJ_putp6.c Compile thumb : proj <= pj_qsfn.c Compile thumb : proj <= pj_release.c Compile thumb : proj <= PJ_robin.c Compile thumb : proj <= PJ_rpoly.c Compile thumb : proj <= PJ_sconics.c Compile thumb : proj <= PJ_somerc.c Compile thumb : proj <= PJ_sterea.c Compile thumb : proj <= PJ_stere.c Compile thumb : proj <= pj_strerrno.c Compile thumb : proj <= PJ_sts.c Compile thumb : proj <= PJ_tcc.c Compile thumb : proj <= PJ_tcea.c Compile thumb : proj <= PJ_tmerc.c Compile thumb : proj <= PJ_tpeqd.c Compile thumb : proj <= pj_transform.c Compile thumb : proj <= pj_tsfn.c Compile thumb : proj <= pj_units.c Compile thumb : proj <= PJ_urm5.c Compile thumb : proj <= PJ_urmfps.c Compile thumb : proj <= pj_utils.c Compile thumb : proj <= PJ_vandg2.c Compile thumb : proj <= PJ_vandg4.c Compile thumb : proj <= PJ_vandg.c Compile thumb : proj <= PJ_wag2.c Compile thumb : proj <= PJ_wag3.c Compile thumb : proj <= PJ_wag7.c Compile thumb : proj <= PJ_wink1.c Compile thumb : proj <= PJ_wink2.c Compile thumb : proj <= pj_zpoly1.c Compile thumb : proj <= proj.c Compile thumb : proj <= proj_mdist.c Compile thumb : proj <= proj_rouss.c Compile thumb : proj <= p_series.c Compile thumb : proj <= rtodms.c Compile thumb : proj <= vector1.c StaticLibrary : libproj.a SharedLibrary : libspatialite.so Install : libspatialite.so => libs/armeabi/libspatialite.so
The resulting library:
$ ls -l ../libs/armeabi/libspatialite.so -rwxr-xr-x 1 mark mark 1560744 2011-03-13 22:23 ../libs/armeabi/libspatialite.so