Compiling native libraries for Android L

By manik August 19, 2014

Preparing your app for Android L ?

While using native executables in our existing Android apps we observed that those executables were no more working with Android L. We came to know that Android has introduced one more security feature starting from Android L i.e
Executable must be PIE (Position independent executable).

To compile a library adhering to above security feature you just need to follow these steps:

  1. Set following LDFLAGS or linker flags : -pie -fPIE
  2. Add --with-pic option while configuring the library.

Some libraries might use different configure options to compile the code with PIC (Position Independent Code) so to check all available configure options for PIC you can use this command:

./configure -h | grep -i pic

If there is no PIC option in configure script then you can try passing -fPIC option with your CFLAGS.

Now, compile the project (make, make install) and it should generate PIE.

To check if you’ve successfully generated a Position Independent Executable (PIE)

You can use “hardening-includes” package on Ubuntu or Debian.

  1. Install “hardening-includes”:
    apt-get install hardening-includes
  2. Usage:
    hardening-check [path-to-executable]

    which will results in an output similar to this:

     Position Independent Executable: yes
     Stack protected: yes
     Fortify Source functions: no, only unprotected functions found!
     Read-only relocations: yes
     Immediate binding: yes

“Position Independent Executable” must be yes for Android L compatible executables.

I’ve compiled couple of projects which are Android L compatible, follow the steps in README to compile them yourself.
curl – Android L compatible
FFmpeg – Android L compatible

For more information about various compilation options read my other post Cross Compiling FFmpeg with x264 for Android

Share this:

Leave a comment

Your email address will not be published. Required fields are marked *


  1. Kevin Cernekee says:

    Note that enabling PIE will fix ‘L’, but prevent the executable from working on ICS. For more info, see:

    Since this breaks the ABI and makes it hard for app developers to support a wide range of Android versions, I have filed a ticket asking Google to revert the change:

  2. Katharine Fauteux says:

    Grateful to you for demonstrating something that is best, and this gives a thought for each one of us to dependably get from some individual paying little regard to the way that that individual is not known, and achievement always for you who have energized every one of us!

  3. Vincenzo Avolio says:

    I’ve already made a pie version of python for android that works both in android K and in Android L. Maybe google has already reverted the change?

    I’ve applied some lines of your ffmpeg_build sh in and indeed I succeeded in building pie version of ffmpeg and ffprobe executable. Now I have both shared library and pie executables. Many thanks to you and to Cedric Fung (

    Vincenzo Avolio