\subchapter{Building a library}{Add a native library to the build system}

After this lab, you will be able to
\begin{itemize}
  \item Add an external library to the Android build system
  \item Compile it statically and dynamically
  \item Add a component to a build
\end{itemize}

\section{Building a static library}

To get the libusb source code, go to \url{www.libusb.org} and download
version 1.0.8. Extract the archive in the \code{external/libusb} folder.

For this library, all the needed \code{.c} files are located in the \code{libusb}
folder and its subfolders. The headers are located in the same folders. Make
the build system generate a \code{libusb-static.so} file.

You will find one missing header that you will need to generate. Indeed, the
\code{config.h} generated by autoconf is not generated at all, because the
Android build system ignores other build systems. You will have to generate it
by yourself.

If successful, the build system should go through the build process and you
should have a directory generated in the \code{out} directory.

\section{Building a shared library}

Now, we will need to build a shared library along with the static one, called
\code{libusb.so}. Use the same \code{config.h} and modify the \code{Android.mk}
file so that it gets compiled. Then, check that the shared object is present in
the \code{out} folder.

\section{Integrate the library into the Android image}

As you can see, your library has been compiled during the build process, but if
you boot the generated image or look inside the \code{out/target/product/system/lib}
folder, you can see that the shared object is not present.

Modify the appropriate files so that in the images, you will have the two 
variants of the library we compiled.
