Can't download iOS dependencies (KMM)
Closed this issue · 19 comments
Hello,
First of all, thank you for providing this library to the KMM community.
I'm working on a KMM project and I wanted to test the tool on it but I wasn't able to do so. The project has targets for Android and iOS (iosX64, iosArm64, iosSimulatorArm64). I took a look in JitPack and apparently, I can't find a kmqtt-common for the mentioned iOS targets.
Am I missing something or is it something from the library side?
Kotlin version - 1.8.10
Error from Gradle
* What went wrong:
Could not determine the dependencies of task ':shared:transformIosMainCInteropDependenciesMetadataForIde'.
> Could not resolve all task dependencies for configuration ':shared:allSourceSetsRuntimeDependenciesMetadata'.
> Could not resolve com.github.davidepianca98.KMQTT:kmqtt-common:0.4.1.
Required by:
project :shared
> Could not resolve com.github.davidepianca98.KMQTT:kmqtt-common:0.4.1.
> Could not get resource 'https://my_artifactory_link/github/davidepianca98/KMQTT/kmqtt-common/0.4.1/kmqtt-common-0.4.1.pom'.
> Could not GET 'https://my_artifactory_link//github/davidepianca98/KMQTT/kmqtt-common/0.4.1/kmqtt-common-0.4.1.pom'. Received status code 403 from server: Forbidden
> Could not resolve com.github.davidepianca98.KMQTT:kmqtt-client:0.4.1.
Required by:
project :shared
> Could not resolve com.github.davidepianca98.KMQTT:kmqtt-clien:0.4.1.
> Could not get resource 'https://my_artifactory_link/github/davidepianca98/KMQTT/kmqtt-client/0.4.1/kmqtt-client-0.4.1.pom'.
> Could not GET 'https://my_artifactory_link/com/github/davidepianca98/KMQTT/kmqtt-client/0.4.1/kmqtt-client-0.4.1.pom'. Received status code 403 from server: Forbidden
build.gradle.kts
sourceSets {
val commonMain by getting {
dependencies {
implementation(com.github.davidepianca98.KMQTT:kmqtt-common:0.4.1)
implementation(com.github.davidepianca98.KMQTT:kmqtt-client:0.4.1)
}
}
}
Hello, JitPack cannot provide the dependencies for Apple targets, I should update the Readme to let the users know. Anyway you can clone the repository, build it and publish it to maven local through Gradle. Then you can add maven local in the repositories of your project in build.gradle and you should be able to use the iOS dependencies. Keep in mind it's not been tested yet as I don't have Apple devices as of now.
Hey, thanks for the reply. I've ended up exploring a little bit the project and doing that afterwards. I was able to integrate it on my project but I didn't succeed to connect the MQTT Client (I'm using HiveMQ for the test). Anyways, I'll probably need to take a deep look on the code since I really wanted to integrate it in my project.
You can let me know what exactly is happening, so we can work together to solve the problem. I'm interested in expanding the supported platforms as much as possible. As I said I wasn't able to test the iOS implementation, but it's the same as on other POSIX platforms.
Sorry, I should have done that on my previous comment.
The error that is being retrieved is: kotlin.Exception: CONNACK not received in 30 seconds
This is my implementation:
val client = MQTTClient(
mqttVersion = 5,
address = "broker.mqttdashboard.com",
port = 8000,
tls = null,
webSocket = true,
clientId = "clientId-myClientAsGhYi",
) {
print("## rjfc ## - ${it.payload?.toByteArray()?.decodeToString()}")
}
client.subscribe(
listOf(
Subscription(
topicFilter = "my_custom_topic",
SubscriptionOptions(Qos.EXACTLY_ONCE)
)
)
)
client.publish(
false,
Qos.EXACTLY_ONCE,
"my_custom_topic",
"hello from KMM".encodeToByteArray().toUByteArray()
)
client.run()
I would be happy to help you in that task, since I can provide support regarding Apple dependencies.
So it looks like the connection is setup correctly but the CONNACK packet doesn't get sent by the server or received. It would be interesting if you could try without websockets first. Or maybe you could even try to setup mosquitto on your computer and try to connect to it from the phone on your local network, so that you can run wireshark or a similar tool and get a packet trace to see exactly what is happening.
Can you also try on test.mosquitto.org?
I have tried to use your exact code on Windows, to check if it was a problem with HiveMQ specifically, but it's working fine. Another option would be to run the code in the emulator (if possible) with Wireshark on the host to check what is happening to the TCP connection. Maybe the CONNECT packet is not even sent for some reason.
Same error on test.mosquitto.org: kotlin.Exception: CONNACK not received in 30 seconds
But this time, an interesting response. I didn't connect to test.mosquitto.org through my simulator (for some reason it was not recognising the host, giving me the error Socket connection failed: failed resolving address.
) but I used my local Mosquitto server. The given error was the same (kotlin.Exception: CONNACK not received in 30 seconds
) but this was what I could sniff on the Wireshark:
Comparing with the previous sniff I sent, looks like he is trying to subscribe before connect ACK but I don't really know if that could be the issue. Therefore, he is not succeeding at writing the topic and the message.
This was what I got from the server logs:
As you can see, at some point he connects with success but closes the connection after the 30 seconds. So, my guess would be that he can somehow communicate with the server but not receive any content from it.
You could try removing the subscribe
and publish
calls before callind run
in your code, so the client will only try to connect. This way we should be able to tell if indeed the problem is the subscribe before the connack. Sending packets before receiving the connack is not a protocol violation, and indeed the server isn't closing the connection. It looks like the client is not reading correctly the data sent by the server. This could be a problem with my specific iOS implementation of the POSIX calls.
Removed the subscribe and publish and the issue remains. The logs keep telling that the client was able to connect and after the 30 seconds the client closes the connection. In the app, the CONNACK error remains as well.
Thank you, I will try to find the problem as soon as possible
Please try to clone the latest version and see if it's working correctly. I was able to test on macosX64 and I got the same problem, which is now solved. I'm hoping you could try it on iOS too.
Error 54 is connection reset by peer, so the broker is closing the connection because of the malformed packet. Are you sure you are matching the MQTT version between client and broker? This could be because the broker uses MQTT 3.1.1 and you are trying to connect with MQTT 5 for example.
Yap, you're totally correct. I forgot completely that and I made the test without having that in mind (MQTT newbie here). I'll test it as soon as I can and give you some feedback again.
Sorry for the delay but I ended up not having time to give you some feedback until today. However, I've noticed that you have added TLS support! Thanks for that! 🙏🏼
I ended up updating the repo but I'm facing another issue:
❌ Error Log
> Task :shared:kspKotlinIosArm64 FAILED
e: Could not find "openssl-ios-arm64" in [/Users/<my-user>/dashtt-shared/shared, /Users/<my-user>/.konan/klib, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/common, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/platform/ios_arm64]
> Task :shared:kspKotlinIosArm64 FAILED
e: Could not find "openssl-ios-arm64" in [/Users/<my-user>/dashtt-shared/shared, /Users/<my-user>/.konan/klib, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/common, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/platform/ios_arm64]
Execution failed for task ':shared:kspKotlinIosArm64'.
> Compilation finished with errors
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
Execution failed for task ':shared:kspKotlinIosArm64'.
> Compilation finished with errors
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
I suspect that the cause may be the fact that, in your openssl.def, you are pointing to your root files. Could you take a look on this?
Thanks in advance!
The def file is just to build OpenSSL. The library should be directly in the KMQTT dependency you are including in your project. Did you recompile KMQTT after updating it and published it to maven local? If yes, then please copy this file https://github.com/davidepianca98/KMQTT/blob/master/kmqtt-common/src/nativeInterop/openssl-ios-arm64.klib to one of the folders in the error while I try to find the problem.
Yap, I've done that but it's not working as well. This is what it retrieves me:
> Task :shared:linkDebugFrameworkIosArm64 FAILED
e: /Users/<my-user>/.gradle/caches/modules-2/files-2.1/com.github.davidepianca98/kmqtt-common-iosarm64/0.4.1/bb81191f70669a5e7a4d32c5fbcd289db7348a41/kmqtt-common is going to be cached, but its dependency isn't: /Users/<my-user>/<my-project>/openssl-ios-arm64
/Users/<my-user>/.gradle/caches/modules-2/files-2.1/com.github.davidepianca98/kmqtt-common-iosarm64/0.4.1/bb81191f70669a5e7a4d32c5fbcd289db7348a41/kmqtt-common is going to be cached, but its dependency isn't: /Users/<my-user>/<my-project>/openssl-ios-arm64
Execution failed for task ':shared:linkDebugFrameworkIosArm64'.
> Compilation finished with errors
I was able to reproduce the problem, but it's not clear why the library isn't getting included. To solve the second error (after copying the library to one of those directories) you can temporarily add this to your gradle.properties
:
kotlin.native.cacheKind.iosX64=none
kotlin.native.cacheKind.iosArm64=none
kotlin.native.cacheKind.iosSimulatorArm64=none