devopvoid / webrtc-java

WebRTC for desktop platforms running Java
Apache License 2.0
248 stars 60 forks source link

How to fetch the jni libs with gradle #23

Closed thelsing closed 2 years ago

thelsing commented 2 years ago

Describe the bug Currently the gradle dependency implementation 'dev.onvoid.webrtc:webrtc-java:0.3.0'

only fetches the java lib. How do I fetch the platform specific ones too?

Could you publish them in maven central separately please?

Or maybe there is some gradle option that fetches all artifacts?

Any help would be appreciated.

polyn0m commented 2 years ago

+1

@thelsing in maven repository exists old native libs. I'm trying build webrtc, but it fails again and again.

@devopvoid lib can more usable if native libs will be include with java part of it.

devopvoid commented 2 years ago

Hi @thelsing, @polyn0m

the platform specific libraries are all uploaded to the Maven central repository (listing). If you include the webrtc-java artifact in your project, it will add the platform specific dependency that includes the native library. But you can include these native library dependencies yourself by providing the platform classifier (windows-x86_64 or linux-x86_64 or macos-x86_64).

Hope it helps.

devopvoid commented 2 years ago

My suspicion here is that probably your Java module setup is not loading the native library. The first step would be to investigate the dependency tree in your IDE and see if the platform specific jar is included.

thelsing commented 2 years ago

Thank you for the fast reply.

After reading https://medium.com/nerd-for-tech/gradle-managing-scope-and-platform-specific-dependencies-5384d6d8ac52 I'm not sure if gradle should pull the correct platform specifc jar automatically.

It works now with:

implementation 'dev.onvoid.webrtc:webrtc-java:0.3.0'
if (osdetector.os.is('windows'))
    implementation 'dev.onvoid.webrtc:webrtc-java:0.3.0:windows-x86_64'
else if (osdetector.os.is('osx'))
    implementation 'dev.onvoid.webrtc:webrtc-java:0.3.0:macos-x86_64'
else if (osdetector.os.is('linux'))
    implementation 'dev.onvoid.webrtc:webrtc-java:0.3.0:linux-x86_64'

Maybe this helps someone else.

javmarina commented 2 years ago

Note that you also need to include the osdetector plugin. I propose an alternative:

import org.gradle.internal.os.OperatingSystem;

...

ext {
    webRtcVersion = '0.3.0'
}

dependencies {
    ...
    implementation "dev.onvoid.webrtc:webrtc-java:$webRtcVersion"
    if (OperatingSystem.current().isWindows())
        implementation "dev.onvoid.webrtc:webrtc-java:$webRtcVersion:windows-x86_64"
    else if (OperatingSystem.current().isMacOsX())
        implementation "dev.onvoid.webrtc:webrtc-java:$webRtcVersion:macos-x86_64"
    else if (OperatingSystem.current().isLinux())
        implementation "dev.onvoid.webrtc:webrtc-java:$webRtcVersion:linux-x86_64"
}

This gist doesn't require an external plugin and guarantees consistent dependency versions. Just edit the webRtcVersion variable and the correct versions will be used.