using kotest FreeSpec on multiplatform module - kotlin-multiplatform

I looks like there's no native module with io.kotest.core.spec.style.FreeSpec, or am I missing something?

According to this build.gradle.kts from the Kotest repo, the only available targets are JVM and JS. I also found an issue with some discussion about K/N support.

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.

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

kotlin native cannot import khttp

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.

Json.NET under Unity3d for iOS

has anyone succeeded to adapt/port Json.NET to a version able to run under Unity3d deployed to iOS (and the webplayer, and android, too, but these seem less problematic), somehow overcoming the AOT issues there?
Or are there plans to release a compatible version of Json.NET?
Many thanks,
Max
You can use netstandard version of Newtonsoft.Json in Unity and it works fine. It seams that this library has changed some inner implementations to not use System.Reflection.Emit for deserialization anymore.
Just be sure that after downloading nuget package you get Newtonsoft.Json.dll from netstandard2.0 folder, not from net45. And also don't forget to specify in link.xml that System.Linq.Expressions.Interpreter.LightLambda class shouldn't be stripped (it's used for deserialization) along with libraries/classes that you use for deserialization (to preserve constructors). Your link.xml should look smth like this:
<linker>
<assembly fullname="Your.Dto.Package.Name" preserve="all" />
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
</assembly>
</linker>
We use this library in all our projects for Android and iOS with IL2CPP and Mono runtimes.
Moreover, unlike Unity's JsonUtility, Newtonsoft.Json fully supports any type of objects, including Dictionary.
Microsoft Example
Newtonsoft Json fails AOT in iOS and also fails at deserializing anything inheriting from KeyedCollection in the webplayer. Here's a version that has been fixed:
JSON .NET For Unity (Supports iOS)
We use MiniJson and so far it serves our json needs well :)
I have been facing the same issue for a while and searched on every nook and cranny of the internet to look for a solution. Here's what worked for me.
I replaced NewtonSoft.Json with NewtonSoft.Json for Unity
Uninstalled NewtonSoft.Json from Unity's Nuget package manager.
Install NewtonSoft.Json for Unity with Unity's package manager. Follow this installation steps
What's the difference?
NewtonSoft.Json for Unity is different from standard NewtonSoft.Json
NewtonSoft.Json does not support AOT targets for IL2CPP builds in Unity
NewtonSoft.Json for Unity supports AOT targets such as all IL2CPP builds (WebGL, iOS, Android, Windows, Mac OS X) and portable .NET (UWP, WP8).
Hope this helps. Cheers!
Nope AFAIK.
LitJson and JsonFX would be alternate choice for Unity3D.
http://wiki.unity3d.com/index.php?title=UnityLitJSON
Have a look at the modified version of LitJson: UnityLitJson
Actually LitJson has some issues and is not always working as expected, so I created a simple JSON-Lib that can handle all Unity3D Types, Enums and arbitrary classes. Find it at GitHub: Tiny-JSON
You can use it very simple:
// encode
Animal a = new Animal(4);
string json = Json.Encode(a);
// decode
IList<Animal> a = Json.Decode<IList<Animal>>("[{\"legs\":4}, {\"legs\":2}]");
Yes, we share code on client and server and use an older version when it was called NewtonSoft.Json. Works in IOS, Android, everything.
Search for NewtonSoft.Json, and you could probably find an archive.

Resources