Monday, May 13, 2013

Cross compiling native audio libraries for Android - Part 2

Update July, 31 2013: The latest git version of libsndfile builds fine without editing sndfile-play.c

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 Download and extract it to your just created src folder:

cd src
tar xvzf libogg-1.3.0.tar.gz

Now try to build it:

cd libogg-1.3.0

This will fail with the following error:

checking host system type... Invalid configuration `arm-linux-androideabi': system `androideabi' not recognized
configure: error: /bin/sh ./config.sub arm-linux-androideabi failed

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 '' 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://
cd ogg

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

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:

Great, the first native library has been built!


If everything went successfully with ogg building vorbis is straight forward:
cd ..
git clone git://
cd vorbis
android-make install


Building flac is just the same:
cd ..
git clone git://

cd flac
android-make install

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.

libsndfile - first try

Now try to build libsndfile the same way:

cd ..
git clone git://
cd libsndfile

Your ogg, vorbis and flac libraries should have been recognized:

Configuration summary :

    libsndfile version : .................. 1.0.26pre5

    Host CPU : ............................ arm
    Host Vendor : ......................... unknown
    Host OS : ............................. linux-androideabi

    Experimental code : ................... no
    Using ALSA in example programs : ...... no
    External FLAC/Ogg/Vorbis : ............ yes

Now build it:

android-make && android-make install

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.