android-ndknative

Android ndk remove "lib" prefix


I am compiling some native code in to a library to use in my app. Everything works fine but something bugging me.

Output of native code gets "lib" prefix added to it so "mylibrary" becomes "libmylibrary.so" and I have toad it as "mylibrary"

Can't I remove this prefix? This might sound odd but keep in mind that I have zero knowledge on compiling native code or on c for that matter


Solution

  • The "lib" prefix is a naming convention in Unix since the early days. This prefix is required when the shared object is used by the linker with -l flag, see more here. The prefix is implied in Java, too, when you use System.loadLibrary(). The prefix is also expected by Android ApkBuilder and the system installer (see details here).

    But if you really want to name you file "mylibrary.so", it is possible to create such file, and load it in Java with System.load(fullpath). You will take care of deployment of this file yourself.