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

cd src
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
tar xvzf libogg-1.3.0.tar.gz

Now try to build it:

cd libogg-1.3.0
android-configure

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 '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:
cd ..
git clone git://git.xiph.org/mirrors/vorbis.git
cd vorbis
./autogen.sh
android-configure
android-make
android-make install

FLAC

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

cd flac
./autogen.sh
android-configure
android-make
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://github.com/erikd/libsndfile.git
cd libsndfile
./autogen.sh
android-configure

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.

No comments:

Post a Comment