Published On: February 23rd, 20173 min read

MuPDF is a useful open source library for adding Pdf viewing. It uses native C/C++ code, which is why it’s necessary to build the library in Android NDK, before integrating it in Android app.

The MuPDF site contains downloads and documentation on the library, as well as concise build instructions.

In this document, we’ll outline a more detail step by step guide for building the library in Linux (Ubuntu 14.04).

1. This document doesn’t discuss integrating the generated library in an Android app, only the build process, and running the sample app.

2. We’ll refer to the instructions in ReadMe.txt file available in the source folder in Step 1 below (i.e. /platform/android/viewer/ReadMe.txt)


JDK, Android SDK, and NDK must be installed in the system (at least API 16).
NDK installation guide

1. Get the MuPDF source code

Check out a copy of the mupdf android viewer source from git:

git clone --recursive git://
2. Set SDK and NDK path in file

It’s in

(You can keep a copy of the file for e.g.

Then change the below 2 lines

3. Adding NDK to PATH

Create an file at /etc/profile.d folder and enter following lines:

export ANDROID_NDK_HOME=/home/raqib/Documents/Android/sdk/ndk-bundle
4. Installing ANT (Several ways mentioned here)

We’ll use

apt-get install ant
5. Adding ANT_HOME and ANT_HOME/bin to PATH

For e.g. my Ant location is /usr/share/ant

Create an file at /etc/profile.d folder

Enter the following content to the file:

export ANT_HOME=/usr/share/ant
export PATH=${ANT_HOME}/bin:${PATH}
6. Activate above environment variables (Step 3 & 5)

We can do that by log out and log in again or simply run below command:

source /etc/profile

We can verify whether Maven is installed successfully or not by type command:

ant -version

The result will be similar to this:

Apache Ant(TM) version 1.9.3 compiled on April 8 2014

(Note: There are several ways to set environment variables as mentioned here. Files with the .sh extension in the /etc/profile.d directory get executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads)

7. Prepare the auto-generated files – a copy of a ‘generated’ directory (not available in download)

According to the readme file, this step is very crucial and often skipped.
On Linux/mac os, give the command

make generate

in the top level directory of the downloaded source code.

8. Build the native code libraries

Change into the platform/android/viewer directory (note, the platform/android/viewer directory, NOT the platform/android/viewer/jni directory!), and execute:


This should build the native code portion.
If this dies with an error in thirdparty/jbig2/os_types.h load this
file into an editor, and change line 43 from:



#elif !defined(HAVE_STDINT_H)

and this should solve the problem.

9. The library *.so file is generated


10. Build the java application


ant debug
11. Running the demo app

If build is successful, the demo Apk will be available in the bin folder


Which we can transfer to the device, install and run.
The ReadMe file also includes steps to install and run in emulator.

Contributor: Raqib Mahmud, Nascenia

Share it, Choose Your Platform!

More to Explore

The Quest for Knowledge Continues. Fuel Your Curiosity.