Android: Import static/shared library

Hi,

can somebody walk me through the import of a static library into an Android project with the Projucer?
I saw the “import static library modules” field in the android exporter but I have no idea how to use that.

I have the library and includes ready in 4 ABIs

Thanks!

So far I do this (I use AWS in this example:

  1. I have the following folder structure:
    39

  2. My Android.mk in the awscore module contains this:

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := awscore
    LOCAL_SRC_FILES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libaws-cpp-sdk-core.so
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

    include $(PREBUILT_SHARED_LIBRARY)

  3. I have added the absolute path of ndk-modules as NDK_MODULE_PATH to my enviroment.

  4. I added the module names to the “Import Shared Library Modules” field of the Android exporter.

I still get the error, that the includes could not be found. The file is there. In my case:

fatal error: ‘aws/core/Aws.h’ file not found

I searched the build.grade and CMakeLists.txt and for the module names I’m trying to include and can’t find any reference to it. Is it possible this has been removed by accident?

Could this please somehow be fixed?
Right now I need to add something along these lines in my CMakelists and build.gradle:

CMakeLists

add_library(“aws-cpp-sdk-core” SHARED IMPORTED)
set_target_properties(“aws-cpp-sdk-core” PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/…/…/…/Dependencies/aws/${ANDROID_ABI}/libaws-cpp-sdk-core.so)

CMakeLists

target_link_libraries( ${BINARY_NAME}
${log}
${android}
${glesv2}
${egl}
“cpufeatures”
“aws-cpp-sdk-core” ← here
“aws-cpp-sdk-sns” ← here
)

build.gradle (the aws dir contains subdirs for each ABI)

sourceSets {
main.jniLibs.srcDirs +=
[“…/…/…/Dependencies/aws”]
}

All these changes are overwritten each time I resave my projucer project.

bump

having the same problem …

2 Likes

We have a similar problem here @tom, @ed95, @fabian any solution?

1 Like

Hello?

2 Likes

tiring

2 Likes

The “Import static library modules” and “Import shared library modules” settings were originally on the old “Android Ant” exporter. They have been moved to the new “Android” exporter in commit ec0485388 (February 2017, between version 4.3.1 and 5.0.0), but they are not doing anything anymore.

In the current (5.4.3) code of Projucer, you can see that androidSharedLibraries is declared, initialized, and associated with the “Import Shared Library Modules” field, but its value is never used. The same is true for androidStaticLibraries.

Yeah, it looks like these are just leftovers from the old Android Ant exporter. I’ll remove the settings from the exporter as it’s confusing that they don’t do anything.

If you’re just linking to prebuilt libs, can’t you use the External Libraries to Link and Extra Linker Flags settings to do what you need?

No, this is not working for me. This will link against any library that has the correct name with no distinction between platforms.

1 Like

@Achder @Wah0airo @alexoz

Did you ever solve this issue or do you still need to edit CMakeLists.txt each time? I’m also trying to import a shared lib, and couldn’t find a way to do it appart from editing CMakeLists.txt.

sry can’t say anything because I haven’t tried since then, but I’d suspect the problem still persists :confused:

but we have to do some android work again in the near future … so please keep us updated and we do likewise :wink:

2 Likes

bump

Is there any proper way to add a static lib in the different architectures directly in the Projucer, or do we need to update the CMakeLists file manually?

1 Like

I’ve found a way to import shared libraries, I’m not sure if the same is with static ones. The libraries are mosquitto and its two dependencies: OpenSSL and crypto. All three are mentioned in the External Libraries to Link section, then for both release types the Header Search Paths point to the include directory of mosquitto, in the Extra Library Search Paths put paths to all the pre-compiled libraries divided into separate architectures. ${ANDROID_ABI} is a variable that hold the currently compiled architecture and should be used there. In my case the third party directory is called “3rdparty” and containes all the precompiled resources.

The last thing is to slightly modify the output CMakeLists.txt file, as it puts strange square brackets over the variables related to the added libraries, remove the brackets. What’s funny is that cmake compiles the app without errors when the square brackets are present, but when running the app the libmosquitto.so is missing from it. Only when the brackets are removed the library is found by the app.

No pictures as I’m a new user to the forum and can only add one embedded element per comment, text is fine, right?

Android: External Libraries to Link

mosquitto
ssl
crypto

Android:Debug and Release: Header Search Paths

../../../3rdparty/mosquitto/include

Android:Debug and Release: External Library Search Paths

../../../3rdparty/openssl-3.0.12/lib-android/${ANDROID_ABI}
../../../3rdparty/mosquitto/lib-android/${ANDROID_ABI}

original square brackets in the CMakeLists.txt

target_link_libraries( ${BINARY_NAME}

    ${log}
    ${android}
    ${glesv2}
    ${egl}
    "cpufeatures"
    "oboe"
    [[mosquitto]]
    [[ssl]]
    [[crypto]]
)

and what they should be

target_link_libraries( ${BINARY_NAME}

    ${log}
    ${android}
    ${glesv2}
    ${egl}
    "cpufeatures"
    "oboe"
    mosquitto
    ssl
    crypto
)

@t0m could this behavior of adding the square brackets be removed? I’m running ProJucer 7.0.8, not that old, so I suppose the latest version still battles the same fight :slight_smile:

I tried that again, this time the libraries are not found anymore. So I guess this is not a clear instruction on how not to fail :frowning: