Help linking the full C++ library to an android project

I need to use the full C++ version of MAVSDK on android, so I’m trying to link the library with a different C++ library that contains app-specific code and JNI Calls.
As the dockcross scripts don’t work on windows, I’ve compiled MAVSDK on a seperate linux machine to a libmavsdk.so file, and am attempting to link it. The “MAVSDK Installed Locally” category of the documentation seems incomplete, and I don’t have much experience with CMakeLists, so I would appreciate help with linking the library. I’ve used include_directories to add the header files from the GitHub release and that seems to work fine, but isn’t enough to compile.

If there’s a better way to use the full C++ api on Android or I’m missing something, please let me know, and apologies for my inexperience. Thanks for your time.

I am newly using mavsdk develop kit.
Can you tell me how to generate libmavsdk.so file?
Thanks

Sadly it has been a while and I do not remember much about this project. Lucky, I wrote down the steps. I can’t vouch for if they’re still accurate, however.

Compiling MAVSDK from source

You’ll need a Linux device or virtual machine to easily compile MAVSDK. You will need to clone the MAVSDK Github, and then combine the steps to build the server for android with the steps to build the whole library. You will need docker to compile for Android.

Assuming you have the cloned repository open, and docker installed, the following should work:

sudo docker run --rm dockcross/android-arm > ./dockcross
sudo chmod +x ./dockcross
sudo ./dockcross cmake -DCMAKE_BUILD_TYPE=Debug -Bbuild/android-arm -H.
sudo /dockcross cmake --build build/android-arm -j8

You’ll find your built library under build/android-arm/src/core/libmavsdk.so

1 Like

Hi, I use your method to generate libmavsdk.so and put it in Android Studio.
But it always appears “Build command failed”.
Do you know what it cause?

Sorry I missed your message, do you still need help? If so, please provide a bit more information as to what you’re trying and what’s going wrong.

I solved it.
Thank you

please help me! I get the following error when compiling MAVSDK using ‘sudo ./dockcross cmake -DCMAKE_BUILD_TYPE=Debug -Bbuild/android-arm -H.’. How should I solve it?

Cloning into 'mavlink'...
HEAD is now at 3b52eac0 add COMPONENT_METADATA, deprecate COMPONENT_INFORMATION (#1823)
Submodule 'pymavlink' (https://github.com/ardupilot/pymavlink.git) registered for path 'pymavlink'
Cloning into '/work/build/android-arm64/third_party/mavlink/mavlink/src/mavlink/pymavlink'...
Submodule path 'pymavlink': checked out 'df6e4d7c37edda3f687bb31db1b3e12a67eab831'
[ 37%] Performing update step for 'mavlink'
[ 50%] No patch step for 'mavlink'
[ 62%] Performing configure step for 'mavlink'
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/work/build/android-arm64/third_party/mavlink/mavlink/src/mavlink/pymavlink/tools/mavgen.py", line 16, in <module>
    from pymavlink.generator import mavgen
  File "/work/build/android-arm64/third_party/mavlink/mavlink/src/mavlink/pymavlink/generator/mavgen.py", line 26, in <module>
    from future import standard_library
ModuleNotFoundError: No module named 'future'
gmake[2]: *** [CMakeFiles/mavlink.dir/build.make:92: mavlink/src/mavlink-stamp/mavlink-configure] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mavlink.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
CMake Error at third_party/cmake/build_target.cmake:51 (message):
  /work/build/android-arm64/third_party/mavlink failed to build!
Call Stack (most recent call first):
  third_party/CMakeLists.txt:31 (build_target)

There was also a github issue, right? Can you link that here and we continue the discussion there.