kotlin native cannot import khttp - ios

I'm having a problem with usage of khttp library (which is supposed to work in Kotlin and provides equal to python's request's library features)
My build.gradle contains those strings:
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
compile "com.github.jkcclemens:khttp:-SNAPSHOT"
}
Project builds with success, but importing with import khttp doesn't work
In general, I'm using kotlin as framework to IOS project, and khttp is needed to connect to longpoll server. If khttp isn't supposed to work in my case so what are my options? Using it's sources aint good idea i think

Try using this:
compile "com.github.jkcclemens:khttp:0.1.0"
And add https://jitpack.io/ as a repository

I know that I might be necrobumping, but if anyone is looking for an answer, they wouldn't be able to get it from the above.
Khttp library is build for kotlin JVM and not native. If you take a look at the source code, you'll be able to notice that it's using Java's libraries for it to function, this for example.
That means that sadly you can't run it on iOS and any platform that doesn't run JVM, as khttp will only run on the JVM platform and won't be able to run on native because of missing libraries.

Related

Not able to use MockK library in KMM project

Could not resolve io.mockk:mockk:1.13.2 for :shared:iosArm64Test Could not resolve io.mockk:mockk:1.13.2 for :shared:iosSimulatorArm64Test Could not resolve io.mockk:mockk:1.13.2 for :shared:iosX64Test
Found that MockK is only supported for jvm target - https://github.com/mockk/mockk/issues/950
But what i know is the unit tests we write on common shared module are meant to be run on local machine (mac/ windows) which do have have JVM installed.
Please can anyone add some light over here. Thanks
You can use mockk only in jvm test sources. If you write common code, and you have native targets, it won't work.
So, you can add jvmTest instead of commonTest and write tests in jvmTest that use mockk. However, that won't test your native code directly.

What is the right project structure for a Kotlin Multiplatform (KMP) project *without* any platform specific code?

Setting up a full "KMP" / "KMM" project seems like overkill, as only the commonMain/commonTest directories would be filled.
All the other templates seem to be platform-specific.
Is there something like a "pure" Kotlin library template?
It would just be a module with only commonMain and commonTest. You would need at least:
A Gradle module
Kotlin config with multiple targets in that module
Common code folders
Whether you put the app code in the same repo or have the shared code in a separate repo is up to you. I'm not sure how much simpler you can make the config, though.
One issue I think you'll run into is the need for platform-specific code on iOS because there are different interfaces for concurrency than you might want for a Kotlin-friendly (I.E. Android) environment. Same for things like default params.
My-KMP-Library
│ build.gradle.kts
└───src
└───commonMain
└───kotlin
└───mynamespace
What makes it multiplatform are the targets you specify in build.gradle.kts.

How to avoid "libraries attached to project that were compiled with kotlin/native compiler" error?

I am working on a Kotlin Multiplatform Mobile project. Tried adding in libraries for KMM, but I am getting
There are __ third-party libraries attached to the project that were compiled with an older Kotlin/Native compiler and can't be read in IDE.
The android project builds without problem so I was wondering if whether this error is only a warning and doesn't not affect the application at all?
Is there anyway to avoid this issue? How can I know if a library could be used for Kotlin Native?
Kotlin/Native doesn't guarantee binary compatability between versions - although as of 1.4 minor versions are experimentally binary backwards compatible. e.g. 1.4.10 should be compatible with 1.4.20 in the same project.
The easiest way to avoid the error is to ensure you're using KMM libraries with the same kotlin version as the kotlin version your project uses. Same goes for the IDE plugin.
Generally kotlin libraries by Jetbrains stay very up to date, as well as bigger libraries like SqlDelight. But smaller third party libraries can fall behind.
This issue is being actively worked on.

Problem using external jar in Jenkins Shared Library

We are using a Jenkins Shared Library to centralize some code for all our (scripted) pipelines. Now we factored out some Groovy code into a .jar library (written in Kotlin, compiled to be Java 8 compatible). We published this library to our in-house maven repo and now want to use it in our Shared Libary.
We are using #Grab to load our library and up until that point it works like a charm. However we are getting NoSuchMethodError's. We pinpointed it down a bit, we are using OkHttp in our Kotlin lib. OkHttp internally uses Okio. When we call methods that internally call OkHttp-Code from our pipeline, everything is fine. However when the OkHttp-Code call Okio internally, we get a NoSuchMethodError.
We already checked the published .jar file, it contains the classes with the methods that seem to be missing. Does anybody have an idea what the issue could be?
While we are at it, we can't access environment variables set on Jenkins in our Kotlin library, is there a way we can fix this?
We figured it out. The problem was, that a Jenkins plugin used an older version of okio internally. Because plugins and shared libraries somehow share the same classpath, okio did not get loaded and the version from the plugin got used, therefore the class was not present.
We fixed this by repackaging all dependencies in our .jar, so package names would not interfere and we can make sure that our specified dependencies are being used.
Looking the dependencies here you have a few problems:
OKHttp - seems to expect some Android libraries
okio - depends on the Kotlin runtime
Any calls to these will result in method not found errors unless you find a way to make them available without causing problems in Jenkins

using import 'dart:html' in flutter - Do I need additional dependencies?

I came across a websocket example that I would like to use. However it uses import 'dart:html';. When I introduce that in my Flutter project seems like its not being picked up. Do I need to add additional dependencies to the pubspec.yaml?
dart:html can't be used in Flutter.
It is for browser applications only.
dart:html also only comes with the regular Dart SDK, not with the Dart SDK shipped with Flutter.
I know this is an old question but let me drop this answer here.
I've searched for a web crawler/scraper for Flutter for a while now. I've tried to use FlutterWebview and also the HTML package but no way. Recently I've found a new package for this.
The advantage of this package is that it is really cross platform as explained:
Cross-platform dart:html that works in the browser, Dart VM, and Flutter.
Typical use cases are:
Cross-platform application development (e.g. Flutter mobile and web versions).
Web crawling and scraping
you can use universal_html for any scraping/crawling purpose
Since the merge of Flutter-web into the main Flutter repository, it's no longer possible to directly add imports for web libraries (e.g. dart:html) in a Flutter project on the main channel when targeting Web, Android and iOS.
Use the universal html package which provides extensive support for multiple platforms and web libraries.
From the root level of your project, command
1.
flutter pub add universal_html
2. import 'package:universal_html/html.dart' as html
This package isn't required to run some web files (e.g. dart:js). In my case, I just had to remove the import 'dart:js' import statement.

Resources