Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using libxml for Android

We have an application working fine for Mac and Windows platform, now targeting for Android and iOS, Application using libxml for parsing of XML data, and my question is ?

1 -- Do i need to build libxml for Android platform or its already there as a part of NDK ?

if need to build any pointers how to start ?

like image 942
Amitg2k12 Avatar asked Aug 21 '12 09:08

Amitg2k12


1 Answers

You have two options:

Write an Android.mk that can successfully build libxml, and depend on the result of that in your main Android.mk. You can try to build libxml natively (using the configure script and make) on your Mac to get an idea of what files need to be built, and if any special flags need to be passed.

Or, Use libxml's configure script and build libxml for Android using the NDK's toolchain. You'll have to do something like this:

NDK_ROOT=/path/to/ndk
API_LEVEL=YOUR_API_LEVEL
SYSROOT=$NDK_ROOT/platforms/android-$API_LEVEL/arch-arm

export CC="$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/Darwin-x86/bin/arm-linux-androideabi-gcc"
export CFLAGS="--sysroot=$SYSROOT"
export LDFLAGS="--sysroot=$SYSROOT"

./configure --host=arm-linux-gnueabi --enable-static --disable-shared
make libxml2.la

Technically the host triplet for Android is arm-linux-androideabi, but most configure scripts don't recognize it, and for our purposes here, -gnueabi is close enough.

I ended up suggesting make libxml2.la rather than just make because the tests weren't building properly. The resulting library will end up in the .libs/ folder.

The second method might be a little easier, but if you intend to build your app for multiple architectures (arm, armv7-a, maybe even x86 and mips), writing your own Android.mk will save you time in the long run.

like image 87
kelnos Avatar answered Nov 19 '22 16:11

kelnos