Droidcon India 2014

Droidcon India’s fourth edition

Cross compiling native Linux libraries for Android

Submitted by Hitesh Sondhi (@hiteshsondhi88) on Wednesday, 22 October 2014


Technical level






Vote on this proposal

Login to vote

Total votes:  +34


Learn how to cross compile and use native linux libraries like FFmpeg/curl for Android.
The new Android Lollipop requires binaries to be PIE executables so I will also cover during the course on how to make binaries compatible with Android Lollipop.


We’ll have hands on session cross compiling native Linux libraries for Android. Will walk through the following steps during the workshop:

  1. Installing Android NDK
  2. Installing required Linux packages
  3. Basic linux compilation and how can we cross compile native Linux projects for Android.
  4. What is pkg-config, how it works on Linux and how can we use it to make our life easier while cross compiling for Android.
  5. Demonstration of compiling curl for Android.
  6. How can we make our binaries compatible with Android Lollipop (i.e Creating PIE binaries).
  7. Demonstration of compiling FFmpeg for Android.
  8. How to add more codecs/features to FFmpeg.
  9. Demonstrating use of these compiled binaries using Java.

In the end will share a shell script that would cover all the steps above and the developer can easily modify it to compile other native Linux libraries.


  1. Basic linux knowledge.
  2. A laptop with Ubuntu 12.04, 14.04 or Debian wheezy.
  3. Basic Android Development Setup.

Optional: (Can do it during the workshop)

  1. Android NDK (https://developer.android.com/tools/sdk/ndk/index.html).
  2. FFmpeg source code (http://ffmpeg.org/releases/ffmpeg-2.4.2.tar.bz2)
  3. curl source code (https://github.com/bagder/curl/archive/curl-7_38_0.tar.gz)
  4. openssl source code (https://github.com/openssl/openssl/archive/OpenSSL_1_0_1j.tar.gz)
  5. x264 source code (ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2)

Speaker bio

Android lover, nodeJS enthusiast, hacker, coder, loves server side scripting.
I’ve been working on Android framework from last 3 years with Vinsol. I’ve worked on
various interesting apps and I am keen to share my experience with the community.

I occasionally write about my technical experience on Vinsol’s blog http://vinsol.com/blog
Android weekly published few of my blog posts in the weekly issues below:

I’ve been maintaining few open source libraries

Connect me on github https://github.com/hiteshsondhi88



  • 1
    Hitesh Sondhi (@hiteshsondhi88) Proposer 4 years ago (edited 4 years ago)

    Problem Statement

    Cross compiling any native linux library is tedious process. To give an example :
          During my project I faced an issue where I needed to merge audio and video. To do so in Android the best way is to use FFmpeg but unfortunately the versions available online were not compatible with all versions of Android and were using an outdated version of FFmpeg.
          This led me to write down few scripts performing all the required steps for cross compilation for Android.
          Also, there is an additional step to compile linux libraries for Android Lollipop as Android has forced a limitation that binaries should be PIE.
           e.g -
    • We need to use Android NDK’s gcc for compilation instead of system’s native compiler.
    • Identifying toolchain based on architecture.
    • Identifying Target device architecture.
    • Resolving dependencies for the native linux library we are compiling.
    • Compilation Flags etc etc

    Layout / Flow of Talk

    The workshop is split into two sections which dive into getting started and advanced explanation of the concepts.
    • Intermediate Talk - Getting Started
      • Necessary setup to perform linux compilation. - 2 min
      • Sample Linux Compilation. - 3 min
      • Necessary setup required to perform compilation of native linux libraries for Android. - 2 min
      • I will talk about how cross compilation works and how can we use NDK to cross compile for Android. - 2 min
      • Take the base scripts and modify them to add curl compile support. - 3 min
      • Compiling Curl for Android. - 5 min
      • Take the base scripts and modify them to add curl compile support with openssl. - 3 min
      • Compiling Curl with Openssl for Android. - 5 min
      • Tell audience how to make above binaries compatible with Android Lollipop (PIE) - 3 min
      • Demo - Show it on Device using sample java application. - 5 min
      • C code to check if processor architecture is armv7 or armv7 neon. - 2 min
      • How to detect processor architecture using java. - 3 min
      • Explain the above Java code which user’s can use to run generated binaries. - 5 min
      • Take the base scripts and modify them to add FFmpeg compilation support with x264. - 5 min
      • Show compilation of FFmpeg with x264. - 10 min
    • Advanced Talk
      • Explain pkg-config. - 3 min
      • Explain base scripts.- 7 min

    Target Audience

    People who want to compile and use linux projects like FFmpeg, curl for Android.

    Take away

    • After this talk you will be able to compile and run most of the linux projects with Android.
    • Scripts which attendees can directly use to cross compile native linux libraries for Android.
    • Sample Java code which users can directly use to run these binaries on Android.

Login with Twitter or Google to leave a comment