Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use Android NDK and JNI to call a C++ function from Kotlin in my Android Studio project.
Here's my Android project structure:
myproject/app/src/main
└───java
│ │
│ └───com.example.myproject
│ │ MainActivity.kt
└───cpp
| │ native-lib.cpp
| │ CMakeLists.txt
| │
| └───mylib
| │ Number.hpp
| | Number.cpp
└───jniLibs
│ libmylib.so
Notice, I've already built this program into libmylib.so, and saved it to src/main/jniLibs. I want to use this built library, rather than Number.cpp directly.
My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.10.2)
project("myproject")
add_library(myproject SHARED native-lib.cpp)
add_library(MYLIB SHARED IMPORTED)
set_target_properties(MYLIB PROPERTIES IMPORTED_LOCATION jniLibs/libmylib.so)
target_link_libraries(myproject MYLIB)
Yet I get this error when building:
C/C++: ld: error: jniLibs/libmylib.so is incompatible with armelf_linux_eabi
How can I get cmake to properly link the library to my project?
–
–
–
The linker error suggests that you are building myproject for a different ABI than the one that libmylib.so was built for.
You can tell Gradle to only build your native code for one or more specific ABI(s) by adding an ABI filter:
android {
defaultConfig {
ndk {
abiFilters 'arm64-v8a'
... other stuff ...
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.