I am working to get Free Type integrated into my current project. However, I'm hitting a wall when running ndk-build and using the library as a PREBUILT_SHARED_LIBRARY, and a different wall when using PREBUILT_STATIC_LIBRARY.
First, when using PREBUILT_SHARED_LIBRARY, the generated .so file is placed into project/obj/local/armeabi and /project/libs/armeabi, but when it attemps to execute arm-linux-androideabi-strip on the library, the following error is thrown:
Install : libfreetype.so => libs/armeabi/libfreetype.so
/usr/local/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip: Unable to recognise the format of the input file `./libs/armeabi/libfreetype.so'
make: *** [libs/armeabi/libfreetype.so] Error 1
make: *** Deleting file `libs/armeabi/libfreetype.so'
At this point, if i copy the generated .so to the libs directory from the obj directory and try to use it anyway, the application will crash with this message in the device console:
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: get_lib_extents[742]: 122 - /data/data/com.example/lib/libfreetype.so is not a valid ELF object
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
I noticed that in my generated output directory, the libfreetype.so file is really just a link to the real generated file of "libfreetype.so.6.9.0". I'm not sure if this is a problem, I thought I read somewhere that this is a "versioned" shared library and that wouldn't work with the NDK. I don't know if there is a way to tell the Free Type make script to not generate such a thing.
So I attempted to switch over to using PREBUILT_STATIC_LIBRARY. This uses the file "libfreetype.a". When running ndk-build, the library is copied to the project/obj/locl/armeabi folder, but NOT to the project/libs/armeabi folder. Manually copying it over, I get this error when running the application:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libfreetype.a: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
Additionally, when i use adb shell and peek into the directory /data/data/com.example/lib it is empty. Whereas, when I use the .so file, it will appear in this folder on the device.
For compiling the free type library, I am essentially going with what is outlined at this link, with system specific changes.
It does specify to compile using the Android NDK compiler, rather than the system's. I can verify when the configure script is ran that it lists the Android compiler as the one to use, and it outputs "libfreetype.a" as well as "libfreetype.so". Within the generated free type folder structure, I've placed an Android.mk file that reads as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libfreetype
LOCAL_SRC_FILES := lib/libfreetype.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/freetype2
include $(PREBUILT_STATIC_LIBRARY)
Then within my projects JNI folder I have the following Android.mk file:
LOCAL_PATH := $(call my-dir)
LOCAL_STATIC_LIBRARIES := libfreetype
$(call import-module,libfreetype)
And finally, I have an Applicaion.mk file:
APP_MODULES := libfreetype