2

I would like to link a different C++ library based on the ABI. I have one version of the lib that works on x86 and one that works on armeabi-v7a. How can I achieve this in Android Studio?

I could not get the solution by googling and I am new to CMake and Gradle. Android as a whole tbh :) So any help is greatly appreciated.

rozina
  • 4,120
  • 27
  • 49

1 Answers1

2

I managed to slove it this way:

set (libs_list "commonLib1" "commonLib2")

if (${ANDROID_ABI} STREQUAL "armeabi-v7a")    
    set(libs_list ${libs_list} "armLib")

elseif ((${ANDROID_ABI} STREQUAL "x86") OR (${ANDROID_ABI} STREQUAL "x86_64"))    
    set(libs_list ${LIBRARIES_LIST} "x86Lib")

endif()

target_link_libraries(native_lib ${libs_list})
rozina
  • 4,120
  • 27
  • 49
  • Android directly pick up the same lib name in different ABI subfolder, if you could name your lib to be same name, create a lib folder, then create sub folders with exact abi names, put abi-lib in its directory. that would work – Gerry Oct 21 '16 at 06:10
  • @Gerry Thanks, I did not know that. However, in my case I actually wanted to load different libraries for different ABIs. – rozina Oct 21 '16 at 06:16
  • @rozina Can you please look at a question I posted? - https://stackoverflow.com/q/52253127/8199772 – ClassA Sep 14 '18 at 04:23