Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silenium-dev/jni-utils
Kotlin utils for platform detection and JNI
https://github.com/silenium-dev/jni-utils
Last synced: about 2 months ago
JSON representation
Kotlin utils for platform detection and JNI
- Host: GitHub
- URL: https://github.com/silenium-dev/jni-utils
- Owner: silenium-dev
- License: agpl-3.0
- Created: 2024-07-26T11:01:54.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T10:58:34.000Z (2 months ago)
- Last Synced: 2024-10-21T15:49:36.141Z (2 months ago)
- Language: C++
- Size: 147 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jni-utils
A Kotlin library for platform specific loading of jni bindings.
## Usage
You can add the dependency to your project as follows:
```kotlin
repositories {
maven("https://reposilite.silenium.dev/releases") {
name = "silenium-releases"
}
}
dependencies {
implementation("dev.silenium.libs.jni:jni-utils:0.1.0")
}
```### Example
File structure:
```
src
└── main
├── kotlin
│ └── Main.kt
└── resources
└── lib
├── linux-x86_64
│ └── libnative.so
└── windows-x86_64
└── native.dll
````Main.kt`
```kotlin
import dev.silenium.libs.jni.NativeLoader
import java.nio.file.Pathfun main() {
// Loads from linux-x86_64/libnative.so on Linux x86_64
// Loads from windows-x86_64/native.dll on Windows x86_64
val result: Result = NativeLoader.loadLibraryFromClasspath(baseName = "native", basePath = "lib")
if (result.isFailure) { // if file not found or failed to load
println("Failed to load library: ${result.exceptionOrNull()}")
return
}
val path = result.getOrThrow() // path to the extracted library file
println("Loaded library: $path")
}
```