mavlink / MAVSDK-Java

MAVSDK client for Java.
68 stars 40 forks source link

MavsdkServer crash for devices at API level lower than 30 #115

Closed divyanshupundir closed 1 year ago

divyanshupundir commented 1 year ago

Android crashes on app start with the following error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "pthread_cond_clockwait" referenced by ...lib/arm64-v8a/libmavsdk_server.so

Upon doing some research, I found that pthread_cond_clockwait is only available for API 30+

@JonasVautherin any idea how to fix this?

divyanshupundir commented 1 year ago

Looks like there have been some changes in the MAVSDK-Server Android build.

JonasVautherin commented 1 year ago

The C++ toolchain got updated to ndk r25b and api 33. It used to target api 23... Could it be that? :thinking:

It was done 15 days ago, so if that's that, any mavsdk-server before this change should work, and fail after it, right?

divyanshupundir commented 1 year ago

I've done some tests. Looks like it's happening from mavsdk-server version 1.2.2

So this is probably the reason.

divyanshupundir commented 1 year ago

Can it be rolled back? Devices below API 30 still make a major chunk of the global market, including the Herelink.

JonasVautherin commented 1 year ago

Yes, I messed up with dockcross, I thought it did not matter. I guess updating the ndk version is fine, but not the api version. I honestly don't really know what it changes at the C++ level :thinking:. I'll try to rollback :+1:

divyanshupundir commented 1 year ago

No issues. NDK and JNI are really tricky territories and difficult to debug. I'm really interested in the new Foreign Memory API for JVM.

But anyway, I'll test the new release when you'll push it and let you know by tomorrow.

JonasVautherin commented 1 year ago

Can you access the tar archive here? Not completely sure how to best share it. If you prefer I can send it to you over the PX4 Slack in a DM.

I built for android-arm64 using dockcross with api 23 (instead of 33). If that works, then I'll update dockcross and will make a release :+1:

divyanshupundir commented 1 year ago

Looks like the transfer has expired. You can send it over Slack, no problem.

I'll also try to figure out how to do a Sonatype SNAPSHOT release. Don't know how you'll do it over MAVSDK C++ side though.

divyanshupundir commented 1 year ago

Also, I feel that you should use NDK r25 instead of r25b because r25 is an LTS version. Also, r25b is the latest version and may be unstable.

divyanshupundir commented 1 year ago

Wait. r25b is an LTS. Please ignore the previous comment.

JonasVautherin commented 1 year ago

Actually, aren't we seeing an issue related to this? We build all our dependencies using the NDK :thinking:, but pthread_cond_clockwait comes from libc...

I am thinking that, since we link libc dynamically, and libc comes from the NDK, maybe we have a mismatch between libmavsdk_server.so (which is now built with ndk r25b) and the libc++_shared.so that we package (with ndkVersion "23.1.7779620")...

divyanshupundir commented 1 year ago

Hmm... It could be. But I don't know how that worked. I just read that thing in a Stack overflow thread which confirmed with the fact that you had updated the min SDK version.

Just give me a few hours to test the new configuration.

JonasVautherin commented 1 year ago

Yes, it's clear that keeping it to API 23 is solving our problem, but I am not sure if that is the "correct fix". It feels like something is wrong, but API 23 is fine with it. But some C++ code bases need a more modern API, because they use code from libc that was not there before. So dockcross will have to update someday, anyway.

I believe that there should be a way to make it work with API 33, because we ship mavsdk-server.aar with libstdc++.so (and that should be the only dependency of libmavsdk_server.so). So our package should be pretty much self-contained :thinking:.

JonasVautherin commented 1 year ago

Ok, I think you were right, and the answer is here:

Problem: Your NDK API level is higher than the API supported by your device.

Solution: Set your NDK API level (APP_PLATFORM) to the minimum version of Android your app supports.

I'll update dockcross right away.

divyanshupundir commented 1 year ago

That's great. Thanks!

JonasVautherin commented 1 year ago

mavsdk-server:1.2.5 should be out on MavenCentral in a few hours, with the updated release :+1:.

divyanshupundir commented 1 year ago

Awesome!