Building mapnik for android

1,075 views
Skip to first unread message

Igor Stassiy

unread,
Aug 9, 2013, 2:51:10 PM8/9/13
to map...@googlegroups.com
Hi,

I am currently trying to build mapnik for android. I managed to build all the (at least strict) dependencies, but not the mapnik itself.

I came across the following project: https://github.com/richq/scons-android, which unfortunately has not been updated for years however it
seems like a good starting point. I wonder if anyone could point me to the right direction or share SConstruct file for building mapnik for android.

Thanks,
Igor

Dane Springmeyer

unread,
Aug 9, 2013, 4:52:24 PM8/9/13
to map...@googlegroups.com
Hi Igor,

I know that other developers are working on this right now. Erik (https://github.com/linqcan) in particular is quite close and just working through final link errors.

Mapnik's scons build system should be able to be made to work, just have to author the right config.py with custom settings for the HOST, CXX, CUSTOM_LDFLAGS, CUSTOM_CXXFLAGS, and PATH_REMOVE to clear out any unwanted include paths like /usr/include (if you are cross compiling).

Dane

--
You received this message because you are subscribed to the Google Groups "mapnik" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapnik+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Igor Stassiy

unread,
Aug 9, 2013, 6:02:50 PM8/9/13
to map...@googlegroups.com
Thanks Dane. I am also wondering if it is possible to remove libboost_filesystem and libboost_python dependencies "easily" for a minimal mapnik build. Those are particularly hard to build for android.

Igor

Dane Springmeyer

unread,
Aug 9, 2013, 8:30:41 PM8/9/13
to map...@googlegroups.com
libboost_python - yes, absolutely it is optional. Just do not build the python bindings

./configure BINDINGS=none

libboost_filesystem - not so easy. In Mapnik master I've been working to move all boost::filesystem calls into `src/fs.cpp` to isolate them. But there are still a few around in `src/datasource_cache.cpp` and `src/font_engine_freetype.cpp` that would need work.

Beyond those spots the only other usage of filesystem is the `tests/cpp_tests` which can be disabled with:

./configure CPP_TESTS=False

Igor, if you can document precisely how you built the Mapnik dependencies that would help as I plan to set up an android environment next week to try my hand at this.

Dane

Dane Springmeyer

unread,
Aug 9, 2013, 8:33:05 PM8/9/13
to map...@googlegroups.com

Igor Stassiy

unread,
Aug 10, 2013, 2:16:14 PM8/10/13
to map...@googlegroups.com, Kirill Afanasyev
Hi Dane,

here is what I did to build the dependencies. All of the dependencies
will be built using Android-NDK script ndk-build. Before you start you
might need to have standalone toolchain (optional). You can create it
having NDK downloaded with the script make-standalone-toolchain.sh.
You will also find attached Android.mk files.

# setup the environment
export LDLAGS="--sysroot=$ANDROID_SYSROOT"
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT"
export CC="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc"

libpng-1.6.3:

# first method:
1. cmake -DCMAKE_BUILD_TYPE=Release
-DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DANDROID_ABI=armeabi-v7a ..
2. make
# second method:
1. ./configure --host=arm-linux-androideabi
--prefix=libpng-1.6.3/android (prefix should be absolute path)
2. make (this is needed only to create the file pnglibconf.h)
3. ndk-build

libxml2-2.9.1:

1. ./configure --host=arm-linux-androideabi
--prefix=libxml2-2.9.1/android (prefix should be absolute path)
2. ndk-build

libfreetype-2.5.0.1:

Compiler complained about mismatch of types in the header and sources for

freetype-2.5.0.1/src/gzip/infutil.h:89
local const uInt inflate_mask[17];

Just redeclare inflate_mask[17] in the source file as "local const
uInt" instead of "local uInt" and you can proceed:

1. CFLAGS="-std=gnu99" ./configure --host=arm-linux-androideabi
--prefix=freetype-2.5.0.1/android --without-zlib (prefix should be
absolute path)
2. ndk-build

For some reason, creating dynamic libraries doesn't work for these
libraries, the linker is complaining about undefined references but
creating static libraries worked. I have little experience with
building libraries for android, but this could mean that the linker is
expecting those references to be satisfied later and actually the
static libraries are missing something (?).

boost_1_54_0:

You will find attached a .jam file for building boost. Replace the
contents of boost_1_54_0/tools/build/v2/user-config.jam with the one I
sent you.

1 . patch the file boost_1_54_0/libs/filesystem/src/operations.cpp:77
to look like:
(this fixes missing header include <sys/statvfs.h> for android,
there is also a discussion thread on this at stackoverflow)

# include <sys/types.h>
# include <sys/stat.h>
# if !defined(__APPLE__) && !defined(__OpenBSD__)
# ifndef ANDROID
# include <sys/statvfs.h>
# else
# include <sys/vfs.h>
# define statvfs statfs
# endif
# define BOOST_STATVFS statvfs
# define BOOST_STATVFS_F_FRSIZE vfs.f_frsize

2. export PATH=$PATH:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/
3. cd boost_1_54_0/tools/build/v2
4. ./bootstrap
5. cd - (go back to boost root)
7. ./bootstrap
8. bjam --without-python toolset=gcc-androidR8d link=static
runtime-link=static target-os=linux --stagedir=android (or depending
on your ndk you can choose gcc-androidR8e)

libicu:

I followed the following post to compile libicu:
http://thebugfreeblog.blogspot.de/2013/05/cross-building-icu-for-applications-on.html

Please let me know if you had any problems with this. I was thinking
to create Android.mk files for all the parts of mapnik, instead of
changing SConstruct. To me this approach seemed slightly easier.

-Igor
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "mapnik" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mapnik/SOQs3hp8BL0/unsubscribe.
> To unsubscribe from this group and all of its topics, send an email to
Android.mk
Android.mk
Android.mk
user-config.jam

Igor Stassiy

unread,
Aug 10, 2013, 3:11:44 PM8/10/13
to map...@googlegroups.com
Just wanted to add, that to compile you would need to edit user-config.jam to provide path for ndk and change architecture in 
<compileflags>-D__ARM_ARCH_5__
<compileflags>-D__ARM_ARCH_5T__
<compileflags>-D__ARM_ARCH_5E__
<compileflags>-D__ARM_ARCH_5TE__

Dane Springmeyer

unread,
Aug 14, 2013, 10:01:57 AM8/14/13
to map...@googlegroups.com, map...@googlegroups.com, Kirill Afanasyev
Hi Igor,

Thanks for the notes. Erik also shared his notes and with that yesterday I worked on cross compiling on OS X with success. You can follow along at https://github.com/mapnik/mapnik-packaging/issues/96

Also note that I pushed a few changes to Mapnik master that make it easier to build on android. I will be working on some docs today. 

Dane
You received this message because you are subscribed to the Google Groups "mapnik" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapnik+un...@googlegroups.com.
<Android.mk>
<Android.mk>
<Android.mk>
<user-config.jam>

Dane Springmeyer

unread,
Aug 14, 2013, 10:03:46 AM8/14/13
to map...@googlegroups.com
I did not need to make these changes for what it's worth. I patched boost filesystem but otherwise just used a stock 1_53 version. This may be because I am using OS X as my host. 

Dane
--

Igor Stassiy

unread,
Aug 17, 2013, 10:12:06 AM8/17/13
to map...@googlegroups.com
Hi Dane,

I almost made mapnik to run on android, I will follow up once I am
done completely. There is just something very fishy going on:

I compiled mapnik and sqlite.input as two separate shared libraries.
In the code of my program I call:

mapnik::datasource_cache::instance().register_datasource(inputfilename);

which returns successfully and sqlite plugin is added. Afterwards I
call load_map method and inside there on line 713 the following code
is called:

boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);

What is strange is that both
datasource_cache::instance().register_datasource and
datasource_cache::instance().create run through this very same code:

at mapnik/include/mapnik/utils.hpp:140
140 static T& instance()
(gdb) n
142 if (! pInstance_)
(gdb)
147 if (! pInstance_)
(gdb)
149 if (destroyed_)
(gdb)
156 pInstance_ = CreatePolicy<T>::create();
(gdb)
159 std::atexit(&DestroySingleton);
(gdb)
163 return *pInstance_;

which means that the singleton of datasource cache is not shared
between my code and the code inside mapnik shared library.

I noticed this because the plugins that were loaded in my code with
the function datasource_cache::instance().register_datasource were
missing inside datasource_cache::instance().create.

What could be the cause of that? On desktop the very same code runs fine.

Thanks,
Igor
> You received this message because you are subscribed to a topic in the
> Google Groups "mapnik" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mapnik/SOQs3hp8BL0/unsubscribe.
> To unsubscribe from this group and all of its topics, send an email to

Dane Springmeyer

unread,
Aug 17, 2013, 11:23:51 AM8/17/13
to map...@googlegroups.com
Hi Igor,

I recommend statically linking your chosen input plugins, which effectively works around this singleton across dll issue because then you don't need to dynamically load the plugin at runtime.

There is a scons option for doing this that you can take a look at and which sets up the proper set of defines. I recall you were thinking of writing your own Android.mk and if so you'll need to set the right defines yourself.

As far as why this issue is happening, with gcc it can occur due to mismatched visibility settings (-fvisibility=hidden for instance) between when Mapnik was compiled and when you app is compiled against Mapnik headers.

Also I have yet to test the SQLite datasource for Mapnik on Android. There is a call in its sqlite_open command to use shared memory which may need disabled if the SQLite version does not ignore it (I doubt libsqlite3 on android has been ported to use ashm?)

Dane

Alexey Tikhvinsky

unread,
Sep 19, 2013, 2:46:44 PM9/19/13
to map...@googlegroups.com
Hi Dane,

Is there any result with building mapnik on Android out of the box?

I'm starting my new hobby project for mapping on android and wanted to use mapnik. Do you have some intermediate result and instructions except those can be found in this topic?

Thank you

Alexey

Claudio Bo

unread,
Apr 29, 2014, 8:11:46 AM4/29/14
to map...@googlegroups.com
Hi,

I'm also interested in porting mapnik for Android, is there any available solution up to now ?

Thanks
Reply all
Reply to author
Forward
0 new messages