Monday, May 13, 2013

Cross compiling native audio libraries for Android - Part 2

In part 1 of this small series of blog posts I've shown you how to set up a cross compile environment for building autotools projects for Android. Now let's ut it to the test and build some audio libraries. To follow this tutorial please create a 'src' subdirectory in your toolchains directory and cd into it:

cd $TOOLS/android-toolchains/arm-linux-androideabi-4.8
mkdir src

Ogg - first try

Let's start with ogg. You can find a source tarball on xiph.org. Download and extract it to your just created src folder:

What's wrong?

This is an error you will frequently encounter. Configure is using a script called 'config.sub' and it doesn't know about arm-linux-androideabi. This doesn't come as much of a surprise as the version shipped with the tarball has a timestamp '2009-11-20'. I'm not sure but I don't think there was a compiler with arm-linux-androideabi back then.

Fortunately, 'config.sub' isn't really part of the actual sources but is generated with a script called 'autogen.sh' that is not part of the source tarball but can be found in the git tree.

Ogg - second try

So, let's clean up and try with ogg from git:

rm -rf libogg-*
git clone git://git.xiph.org/mirrors/ogg.git
cd ogg

This directory doesn't contain the 'configure' script, yet. So we have to create it by running 'autogen.sh':

./autogen.sh
android-configure
android-make
android-make install

These commands should run without problems. If you run into issues though you are probably missing some development tools in your Linux installation. Install them using apt-get, yum or whatever your distribution is using.

Now, let's verify our installation:

ls $TOOLS/android-toolchains/arm-linux-androideabi-4.8/lib | grep ogg

Should yield output similar to this:

libogg.a
libogg.la
libogg.so
libogg.so.0
libogg.so.0.8.0

Great, the first native library has been built!

Vorbis

If everything went successfully with ogg building vorbis is straight forward:

FLAC

UPDATE: Currently FLAC from git won't build. Please, checkout the last working version d35b21e7b92a46fb64307f7b43f173f5efa35192 before building.Update: I'm currently getting an error on the first run of android-make related to 'docbook-to-man'. The second run of android-make runs fine.

Done! You now have a complete set of libsndfile, libogg, libvorbis, libflac build for Android!But there have been lots of warnings in the build process of libsndfile. So we should probably perform some tests before using it in an Android project. So the next part will show how to use those libraries and how to run the libsndfile test suite.