Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch the jni libs with gradle #23

Closed
thelsing opened this issue Sep 5, 2021 · 5 comments
Closed

How to fetch the jni libs with gradle #23

thelsing opened this issue Sep 5, 2021 · 5 comments
Assignees

Comments

@thelsing
Copy link

thelsing commented Sep 5, 2021

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
Copy link

polyn0m commented Sep 6, 2021

+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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

thelsing commented Sep 6, 2021

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.

@thelsing thelsing closed this as completed Sep 6, 2021
@javmarina
Copy link

javmarina commented Sep 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants