Amit Yadav
Amit Yadav

Reputation: 1039

How to link .a to .so and create new .so for android

I have an existing android project where a .so (say existing.so) is packaged and loaded in some .aar (say existing.aar). That existing.so file exposed a symbol(funcion) which my .a (my.a) static library will use. How to include my.a file in that particular project so that it get links to existing.so ? Should a new .so made linking my.a and existing.so ? I can add cmake or ndk dependency in that existing project.

Upvotes: 0

Views: 938

Answers (1)

Mykola Khyliuk
Mykola Khyliuk

Reputation: 1413

If the native prebuilt libraries are provided via the .aar prefab, here's a link from Android Developers of how to do it, if not, you need to do it like you would for a normal CMake project:

  1. Lay your prebuilt libraries in such order:
libs/${ANDROID_PLATFORM}/${ANDROID_ABI}/existing
libs/${ANDROID_PLATFORM}/${ANDROID_ABI}/my

e.g.:

libs/android-28/x86_64/existing/lib/existing.so
libs/android-28/x86_64/existing/include/existing.h
libs/android-28/x86_64/my/lib/my.a
libs/android-28/x86_64/my/include/my.h
  1. Add paths to APPEND CMAKE_FIND_ROOT_PATH in your project .so:
list(APPEND CMAKE_FIND_ROOT_PATH libs/${ANDROID_PLATFORM}/${ANDROID_ABI}/existing)
list(APPEND CMAKE_FIND_ROOT_PATH libs/${ANDROID_PLATFORM}/${ANDROID_ABI}/my)
  1. Now you can use them from your project .so:
find_library(existing_lib existing)
find_library(my_lib my)

add_library(project SHARED <source_files>)
target_link_libraries(project existing_lib my_lib)

Upvotes: 2

Related Questions