Since the precompiled library is already built, you need to use the IMPORTED flag to tell CMake that you only need to import it into your project:
add_library( imported-lib
SHARED
IMPORTED )
Then you need to use the set_target_properties() command to specify the path to the library, like the code below.
set_target_properties( # Specifies the target library.
imported-lib
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
imported-lib/src/${ANDROID_ABI}/libimported-lib.so )
In order for CMake to find your header file during compilation, you need to use the include_directories() command and pass your header file address in:
include_directories( imported-lib/include/ )
Use the target_link_libraries() command in the CMake build script to associate the prebuilt library with your local library:
When you build your APP, Gradle will automatically package the imported libraries into your APK. You can use APK Analyzer to check.
But if you can get the source code, I don’t recommend linking to .so because it may be incompatible with specific platforms. For example, the .so dynamic library compiled on the Linux platform cannot run on the arm platform (such as Android).
Reference:
Have fun using C/C++ in Android Studio 2.2
Relocations in generic ELF (EM: 62) Wrong solution
Take CMake as an example:
Since the precompiled library is already built, you need to use the IMPORTED flag to tell CMake that you only need to import it into your project:
Then you need to use the
set_target_properties()
command to specify the path to the library, like the code below.In order for CMake to find your header file during compilation, you need to use the include_directories() command and pass your header file address in:
Use the
target_link_libraries()
command in the CMake build script to associate the prebuilt library with your local library:When you build your APP, Gradle will automatically package the imported libraries into your APK. You can use APK Analyzer to check.
But if you can get the source code, I don’t recommend linking to .so because it may be incompatible with specific platforms. For example, the .so dynamic library compiled on the Linux platform cannot run on the arm platform (such as Android).
Reference:
Have fun using C/C++ in Android Studio 2.2
Relocations in generic ELF (EM: 62) Wrong solution