FreeType Prebuilt Static/Shared Libraries not Copying/Linking

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

FreeType Prebuilt Static/Shared Libraries not Copying/Linking

Steven Gores-Todd
Hello,

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

Loading the library in code looks like this:
static {
        System.loadLibrary("freetype");
    }

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/Vqfgn0B6-ZAJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: FreeType Prebuilt Static/Shared Libraries not Copying/Linking

David Turner
You cannot take a prebuilt library that was not built with the NDK toolchain and use it with ndk-build, this is true for both static and shared libraries.

The fact that your prebuilt is a versioned shared library means you're taking it from a non-Android Linux distribution. This cannot work, period. You will have to rebuild FreeType from sources (and it shouldn't be terribly difficult).

On Thu, Dec 20, 2012 at 7:07 AM, Steven Gores-Todd <[hidden email]> wrote:
Hello,

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

Loading the library in code looks like this:
static {
        System.loadLibrary("freetype");
    }

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/Vqfgn0B6-ZAJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: FreeType Prebuilt Static/Shared Libraries not Copying/Linking

Steven Gores-Todd
Hi,

To reiterate, I've built FreeType from sources using the NDK toolchain. At least, as far as I know all aspects of the compilation were done using the NDK. the website I linked to in the previous email goes over setting the environment and ensuring the correct compiler is invoked. In any case, I've since moved on to using a bitmap/canvas to draw text, and then creating a texture from that bitmap. Unless anyone can spot something wrong in the linked guide, I likely won't be revisiting this issue for some time.

Steven Gores-Todd

On Mon, Dec 31, 2012 at 10:21 AM, David Turner <[hidden email]> wrote:
You cannot take a prebuilt library that was not built with the NDK toolchain and use it with ndk-build, this is true for both static and shared libraries.

The fact that your prebuilt is a versioned shared library means you're taking it from a non-Android Linux distribution. This cannot work, period. You will have to rebuild FreeType from sources (and it shouldn't be terribly difficult).


On Thu, Dec 20, 2012 at 7:07 AM, Steven Gores-Todd <[hidden email]> wrote:
Hello,

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

Loading the library in code looks like this:
static {
        System.loadLibrary("freetype");
    }

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/Vqfgn0B6-ZAJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: FreeType Prebuilt Static/Shared Libraries not Copying/Linking

David Turner


On Mon, Dec 31, 2012 at 8:52 PM, Steve Gores-Todd <[hidden email]> wrote:
Hi,

To reiterate, I've built FreeType from sources using the NDK toolchain. At least, as far as I know all aspects of the compilation were done using the NDK. the website I linked to in the previous email goes over setting the environment and ensuring the correct compiler is invoked. In any case, I've since moved on to using a bitmap/canvas to draw text, and then creating a texture from that bitmap. Unless anyone can spot something wrong in the linked guide, I likely won't be revisiting this issue for some time.


Ah I see, sorry for the confusion, here's some clarification then:

1/ First of all, a static library is not a loadable piece of code, there is no way you can use it in an .apk and use it. The only thing that will work is a shared library.

2/ As far as I understand, the FreeType build system uses libtool, which by default always creates versioned libraries. Unfortunately, these are not supported by Android, and ELF mandates that the full, versioned, library name be hard-coded in the ELF .dynamic section. In other words, you can't simply rename the file (nor use symlinks instead).

A possible work-around for this is to create a shared library from the static one, i.e. something like:

include $(CLEAR_VARS)
LOCAL_MODULE := libfreetype
LOCAL_WHOLE_STATIC_LIBRARY := libfreetype_static
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libfreetype_static
LOCAL_SRC_FILES := path/to/libfreetype.a
include $(PREBUILT_STATIC_LIBRARY)

I believe this should work, if not please let me know.

Another option is to modify/configure the FreeType build system to add the '-avoid-version' flag when invoking libtool.

An even better option would be to patch libtool to avoid generating versioned libraries when cross-compiling to Android. I thought recent versions of libtool already did this, but I may be wrong.

Hope this helps.
 
Steven Gores-Todd

On Mon, Dec 31, 2012 at 10:21 AM, David Turner <[hidden email]> wrote:
You cannot take a prebuilt library that was not built with the NDK toolchain and use it with ndk-build, this is true for both static and shared libraries.

The fact that your prebuilt is a versioned shared library means you're taking it from a non-Android Linux distribution. This cannot work, period. You will have to rebuild FreeType from sources (and it shouldn't be terribly difficult).


On Thu, Dec 20, 2012 at 7:07 AM, Steven Gores-Todd <[hidden email]> wrote:
Hello,

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

Loading the library in code looks like this:
static {
        System.loadLibrary("freetype");
    }

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/Vqfgn0B6-ZAJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.