I have been dealing with this issue for a couple of days now. I Built the .so library using cmake under visual studio using the fallowing settings:
CMakeList.txt:
cmake_minimum_required (VERSION 3.8)
set(ANDROID_STL c++_static)
set(CMAKE_TOOLCHAIN_FILE C:/Microsoft/AndroidNDK/android-ndk-r21d/build/cmake/android.toolchain.cmake)
project("GetValsDudeLib").
So far I have been unable to find any examples online
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_ANDROID_ARCH arm)
set(CMAKE_SYSTEM_NAME ANDROID)
set(CMAKE_ANDROID_NDK "C:/Microsoft/AndroidNDK/android-ndk-r21d")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang5.0)
set(CMAKE_SYSTEM_VERSION 23) # API level
set(CMAKE_ANDROID_ARCH_ABI x86)
file(GLOB GetValsDudeSRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
add_library (GetValsDudeLib STATIC ${GetValsDudeSRC})
CMakeSetting.json
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}outbuild${name}",
"installRoot": "${projectDir}outinstall${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "gcc-arm" ],
"variables": []
}
]
}
I added the the reference to the android native activity project:
Added headers folder path. Project properties C/C++ => Additional Include Directories.
Added library (.so) folder path. Project properties Linking => input=> Additional Library Directories.
Specified Library. Project properties Linking => input=> Library Dependencies (set that to "GetValsDudeLib").
After that I am able to create an instance of the class provided by the Library (GetValsDude) and build. It runs with no issues. But if I try to use a method of the object (AddOne(int)) it fails with the fallowing exception:
1>C:Program Files (x86)Microsoft Visual Studio19ProfessionalMSBuildMicrosoftVCv160Application TypeAndroid.0Android.Common.targets(119,5): error MSB6006: "clang.exe" exited with code 1.
1> 263 Warning(s)
1> 1 Error(s)
1>
Looking into the logs I found the following:
...
1> C:MicrosoftAndroidNDKandroid-ndk-r21dtoolchainsx86-4.9prebuiltwindows-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/binld: Opened new descriptor 10 for "x86DebuglibRevEngineAndroid.so"
1> undefined reference to 'GetValsDude::AddOne(int)'
...
So obviously there is a failure Linking GetValsDude header to the .so library.
Any help will be greatly appreciated.
Source: Windows Questions C++