how to include prebuilt shared libraries in apk with eclipse

18,744

Solution 1

The include appears to be misspelt:

include $(PREBUILD_SHARED_LIBRARY)

should be

include $(PREBUILT_SHARED_LIBRARY)

Solution 2

Found the solution!! LOCAL_SRC_FILES can not have absolute or relative paths, just the filename. The path must be set in LOCAL_PATH.

So in my case, instead of:

LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so

I have now:

LOCAL_PATH := $(FOO_PATH)
LOCAL_SRC_FILES := libfoo.so

And this works ok.

Solution 3

In eclipse, i add a static library by copying the file in the path project/libs/armeabi/ and rebuild the project after cleaning it. This includes the .so in the apk.

Share:
18,744
Sasha Nikolic
Author by

Sasha Nikolic

Updated on June 14, 2022

Comments

  • Sasha Nikolic
    Sasha Nikolic almost 2 years

    I have a shared library libfoo.so and need to use it in my android app.

    My first try was to have in Android.mk:

    include $(CLEAR_VARS)
    LOCAL_MODULE := test
    LOCAL_SRC_FILES := test.cpp
    LOCAL_LDLIBS := -L$(PATH_TO_FOO) -lfoo
    include $(BUILD_SHARED_LIBRARY)
    

    in my activity, I have:

    statis
    {
        System.loadLibrary("foo");
    }
    

    This builds correctly, however I noticed that created apk doesnt include libfoo.so (also I see it is not copied to libs/armeabi). I guess for that reason I have UnsatisfiedLinkError when executing my app.

    I saw in some other posts that I need to add $(PREBUILD_SHARED_LIBRARY), so I add the following to my Android.mk:

    include $(CLEAR_VARS)
    LOCAL_MODULE:= foo
    LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so
    include $(PREBUILD_SHARED_LIBRARY)
    

    But now I am getting the build error:

    foo: LOCAL_SRC_FILES points to a missing file.
    

    I am sure that the path is correct. Note that the libfoo.so was having origionally the version number at the end, though I had to remove it (and leave only .so) since ndk-build complained.

    What am I doing wrong?

  • Chaitanya Chandurkar
    Chaitanya Chandurkar over 11 years
    hey.. can you put some light on it. m facing same problem. i am having 3 .so files to be loaded what should i write in .mk file?
  • Paul Du Bois
    Paul Du Bois about 11 years
    Downvote. LOCAL_SRC_FILES can definitely contain relative paths.
  • WindRider
    WindRider over 10 years
    This doesn't work for me (ADT22, Indigo, ndk-r9). The lib gets deleted on build.
  • Kadinski
    Kadinski over 7 years
    Can it have absolute paths?