Failed to run mavsdk_server in react native app on Android

Hi all,

Context:
I’m trying to build an app on Android with React Native and using MAVSDK in it. It works like a charm if I run MAVSDK-Java client on the react app (on my device) and mavsdk_server running on a linux host. However my goal is to have both client and server on the app.

Error:
When I add mavsdk_server in my app with implementation 'io.mavsdk:mavsdk-server:0.6.0', it fails with the following error:
More than one file was found with OS independent path 'lib/arm64-v8a/libc++_shared.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

Root cause:
It seems that React Native already have a libc++_shared.so library and don’t know which one to load (supposition). I tried some solutions on React Native side but none of them work (same issue for other SDK that MAVSDK).

Fix:
None… Or at least not on React Native side. So I was wondering if I can do some adaptation with MAVSDK server. Is it possible not to have this libc++_shared.so ? I tried a build from source as well but I don’t get what I need to do with the libmavsdk_server.so generated. Do you think I could avoid the use of this libc++_shared.so if I include the library in another way than with the .aar library ?

This is a specific case and I don’t have the skills to figure it out alone… So if someone has an idea of what I could do to fix that problem this is more than welcome ! :slight_smile:

Ok so I found a solution to avoid this issue.

Build the mavsdk_server from source and change in the gradle:

  defaultConfig {
   ...
    externalNativeBuild {
        cmake {
            arguments "-DANDROID_STL=c++_shared"
        }
    }

to:

  defaultConfig {
   ...
    externalNativeBuild {
        cmake {
            arguments "-DANDROID_STL=c++_static"
        }
    }

Not sure if it is the best solution but now I can finally run the mavsdk_server with a reactive app. Gosh I’m happy :grin:

1 Like

Hello, I have compiled aar mavsdk server 0.9.0 with c++_static flag and I have error with react native app (dlopen failed: cannot locate symbol “_ZNSt6__ndk14__fs10filesystem8__statusERKNS1_4pathEPNS_10error_codeE”)
Do you have any help to know what the problem might be?
Thanks.