Comments (8)
Hello, how did you include the dependency in gradle? Also it looks like you are using Kotlin 1.7.0, I have yet to try to compile with that version but I will check soon.
from kmqtt.
I am including the dependency by adding this to the build.gradle.kts
file into the sourceSets block.
commonMain {
dependencies {
implementation("com.github.davidepianca98.KMQTT:kmqtt:0.3.2")
}
}
The resulting build file looks like this. It is the default template that jetbrains is using for kotlin native projects only with the added dependency.
plugins {
kotlin("multiplatform") version "1.7.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven(url = "https://jitpack.io")
}
kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
nativeTarget.apply {
binaries {
executable {
entryPoint = "main"
}
}
}
sourceSets {
commonMain {
dependencies {
implementation("com.github.davidepianca98.KMQTT:kmqtt:0.3.2")
}
}
val nativeMain by getting
val nativeTest by getting
}
}
For now i am trying out the library in jvm and kotlin 1.7.0 and it working great so far, but cannot get it to work with native.
from kmqtt.
Unfortunately Kotlin Native doesn't provide OpenSSL bindings so I usually compile my version using a script. Apparently this doesn't get included in the library files you get from Jitpack. If you want you can download the prebuilt version from here https://github.com/davidepianca98/KMQTT/blob/master/src/nativeInterop/openssl-linux-x64.klib and include it with the following code changing the directory.
val linuxArm64Main by getting {
dependencies {
implementation(files("src/nativeInterop/openssl-linux-x64.klib"))
}
}
If, for whatever reason, you do not trust the prebuilt library you can build it yourself with Docker and the files in this directory: https://github.com/davidepianca98/KMQTT/tree/master/src/linuxX64Main/resources.
I will be looking for an easier way to do this, but for now this is it unfortunately.
from kmqtt.
I must be missing something compileKotlinNative
task but in linkDebugExecutableNative
.
e: Could not find "openssl" in [/home/fjerabek/mqttTest, /home/fjerabek/.konan/klib, /home/fjerabek/.konan/kotlin-native-prebuilt-linux-x86_64-1.7.0/klib/common, /home/fjerabek/.konan/kotlin-native-prebuilt-linux-x86_64-1.7.0/klib/platform/linux_x64]
Execution failed for task ':linkDebugExecutableNative'.
> Compilation finished with errors
When i add the klib file to one of those locations and change the name to openssl.klib
gradle complains about caching
/home/fjerabek/.gradle/caches/modules-2/files-2.1/com.github.davidepianca98.KMQTT/kmqtt-linuxx64/0.3.2/704c50f7b3bf5fd394f044a485dbba73cdc81f59/kmqtt-linuxx64-0.3.2 is going to be cached, but its dependency isn't: /home/fjerabek/mqttTest/openssl
from kmqtt.
I tried creating a brand new Kotlin Native project, then i added openssl-linux-x64.klib
in the src
directory and modified the build gradle file in the following way (I commented the choice of the platform because I am on Windows and I wanted to build for Linux).
plugins {
kotlin("multiplatform") version "1.7.0"
}
group = "me.x"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven(url = "https://jitpack.io")
}
kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
//val nativeTarget = when {
// hostOs == "Mac OS X" -> macosX64("native")
// hostOs == "Linux" -> linuxX64("native")
// isMingwX64 -> mingwX64("native")
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
//}
val nativeTarget = linuxX64("native")
nativeTarget.apply {
binaries {
executable {
entryPoint = "main"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.github.davidepianca98.KMQTT:kmqtt:0.3.2")
}
}
val nativeMain by getting {
dependencies {
implementation(files("src/openssl-linux-x64.klib"))
}
}
val nativeTest by getting
}
}
Then I made this main file:
import mqtt.broker.Broker
fun main() {
Broker().listen()
}
And finally I ran linkDebugExecutableNative
and it's compiling correctly the binary file and it's running correctly.
Please try to check for differences and let me know if changing your setup makes it work.
from kmqtt.
This is weird. The same build script works on windows (I tried it on my windows machine) but not on linux. I tried cleaning the build cache and still no difference. The gradle versions are the same. I also tried it inside wsl to try other "linux" system and i cannot get it build in wsl too.
from kmqtt.
You are right, I have no idea what's going on, because linkReleaseExecutableNative
works but linkDebugExecutableNative
doesn't. I will continue to try to find the issue but it could be something wrong with the Kotlin build system.
from kmqtt.
Solved in 0.3.3
from kmqtt.
Related Issues (11)
- Can we use it in Android App as a background process? HOT 1
- Suggestions HOT 7
- Can we compile this code for android and iOS ? HOT 1
- HTTP header matching should be case insensitive to support more clients HOT 2
- Can't download iOS dependencies (KMM) HOT 19
- Can't use client library for macos arm 64 HOT 4
- Recurring crash of Client on JVM HOT 1
- Failing to compile with Kotlin and Gradle KTS HOT 4
- "Unable to parse TLS packet header"-error caused by 0-byte-channel-read HOT 4
- Username and Password in the PacketInterceptor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kmqtt.