Question

I want to use libjpeg.so in my android project.

I have precompiled shared library.

Build script in my project:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libjpeg

LOCAL_SRC_FILES :=../lib1/libjpeg.so

include $(PREBUILT_SHARED_LIBRARY)

But what do i get.

source file lib1/libjpeg.so - 1 290 798 bytes

but file after building libs/armeabi/libjpeg.so - 247 236 bytes

I have analyse this 2 files - the second is just truncated

And of course i have "java.lang.UnsatisfiedLinkError"

Why file truncated ?

Was it helpful?

Solution

The problem is that NDK build system strips all prebuilt shared libraries when copying them to destination folder.

If you really need to use a libjpeg as shared library, then I would suggest that you run a post build script to copy the original file to the destination folder overwriting the stripped one.

The best solution is to prebuild a libjpeg.a static library and then you can avoid stripping like this:

include $(CLEAR_VARS)
LOCAL_MODULE := libjpeg
LOCAL_SRC_FILES :=../lib1/libjpeg.a
include $(PREBUILT_STATIC_LIBRARY)

...

include $(CLEAR_VARS)    
LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := mylib.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../lib1/include/
LOCAL_WHOLE_STATIC_LIBRARIES := libjpeg
...
include $(BUILD_SHARED_LIBRARY)

Notice the LOCAL_WHOLE_STATIC_LIBRARIES which turns off the stripping for these libs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top