Compiling native libraries for Android L

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

Tagged as:

3 thoughts on “Compiling native libraries for Android L

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

    http://forum.xda-developers.com/google-nexus-5/development/fix-bypassing-pie-security-check-t2797731
    https://plus.google.com/+Chainfire/posts/ZtXAhw164QD

    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:

    https://code.google.com/p/android-developer-preview/issues/detail?id=888

  2. 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. 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 https://github.com/hiteshsondhi88/ffmpeg-android 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 (https://vec.io/posts/how-to-build-ffmpeg-with-android-ndk).

    Vincenzo Avolio

Leave a Reply

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