Refers to Kotlin Multiplatform projects, aimed to share codebase between JVM, JS, Android, and Native
Questions tagged [kotlin-multiplatform]
1324 questions
77
votes
2 answers
Check your module classpath for missing or conflicting dependencies
I have a project with Java and Kotlin, which I am able to successfully run and build. However, when I open the project in IntelliJ, I see the same error in many of the project files.
The error is "Cannot access class 'java.lang.String'. Check your…

MadLax
- 1,149
- 3
- 10
- 13
22
votes
2 answers
@Parcelize in multi-platform project
I'd like to create a class in a multi-platform project, and use Parcelize to make it Parcelable in the Android version.
So in my lib-common project, I tried:
expect annotation class Parcelize()
expect interface Parcelable
@Parcelize
data class…

Cactus
- 27,075
- 9
- 69
- 149
21
votes
1 answer
Kotlin Multiplatform Mobile targetSdk deprecated
I set up my build.gradle.kts file in the shared module of my KMM project like the following snippets shows:
android {
namespace = "com.my.project"
compileSdk = 33
…

J. Hegg
- 1,365
- 11
- 31
20
votes
2 answers
Generate UUID on kotlin-multiplatform?
Are there any kotlin-multiplatform common functions to get a UUID/GUID?
// ideally something like this
val newUUID = UUID() // "1598044e-5259-11e9-8647-d663bd873d93"
println("newUUID = $newUUID")
I'd prefer not to make separate Android and iOS…

Veener
- 4,771
- 2
- 29
- 37
19
votes
3 answers
Listen to Kotlin coroutine flow from iOS
I have setup a Kotlin Multiplatform project and attached a SQLDelight database to it. Its all setup and running correctly as i have tested it on the android side using the following:
commonMain:
val backgroundColorFlow: Flow =
…

Wazza
- 1,725
- 2
- 17
- 49
18
votes
0 answers
Is there anyway we can create flavored versions of Kotlin Multiplatform build files like dev and prod?
I have a requirement where I want to have different set of data to be shipped with the library generated by kotlin multiplatform module for different flavors like dev and prod.
In an Android project, we can do with productFlavors in the app's…

Paresh Dudhat
- 1,166
- 1
- 14
- 28
17
votes
2 answers
Using kapt with multiplatform subproject
I have the following project structure
root-project
│ build.gradle.kts
│
└───multiplatform-project
│ │ build.gradle.kts
│ │
│ └───src
│ │ kotlin
| | js
│
└───simple-kotlin-project
│ build.gradle.kts
So there are…

Egor Okhterov
- 478
- 2
- 9
- 34
17
votes
3 answers
Handling Exception in HttpClient Ktor
I have written a common code in a common module as below and tested in JS environment
val response = client.post(url) {
body = TextContent("""{"a":1,"b":2}""", ContentType.Application.Json)
}
if (response.status !=…

andylamax
- 1,858
- 1
- 14
- 31
16
votes
2 answers
KMM: Compilation failed: Unexpected IrType kind: KIND_NOT_SET
I'm trying to run tests in the shared library.
Setup (versions should be the same for both machines - all are up to date as of today):
Kotlin 1.6.21 (tried 1.6.20 and 1.6.10)
OpenJDK 11.0.15 (via Homebrew)
IntelliJ
Build #IC-221.5591.52, built on…

peter.o
- 3,460
- 7
- 51
- 77
16
votes
2 answers
Kotlin Multiplatform Configuration issue
I continue getting Gradle configuration error in my KMP + Jetpack Compose project
A problem occurred configuring project ':shared'.
Configuration with name 'testApi' not found.
My setup is:
Android Studio Arctic Fox 2020.3.1 Canary 3
Project…

Андрій Пугач
- 307
- 3
- 10
16
votes
1 answer
How to Implement Custom Cache Mechanism with Kotlin Multiplatform(Android, iOS) Ktor Client
I am working on Kotlin Multiplatform Project. I used Ktor Client for Network calls. I want to cache some request based on some custom logic not based on response header.
HttpCache feature provided by Ktor is Response Header driven and I am not able…

Randheer
- 984
- 6
- 24
15
votes
4 answers
Sqldelight database schema not generated
I have a KMM project and want to use SqlDelight library, but when I build the project database schema not generated and table entities also.
actual class DatabaseDriverFactory(private val context: Context) {
actual fun createDriver(): SqlDriver…

Jemo Mgebrishvili
- 5,187
- 7
- 38
- 63
15
votes
1 answer
How to convert Kotlin ByteArray to NsData and viceversa
Fighting with a Kotlin Multiplatform project I have ended with the problem of needing to work with NsData on my iOS platform from the sharedModule working with Kotlin Native.
Because of this, I need to transform objectiveC NsData to Kotlin ByteArray…

Francisco Durdin Garcia
- 12,540
- 9
- 53
- 95
15
votes
5 answers
Kotlin Multiplatform: How to mock objects in a unit test for iOS
I'm working on a Kotlin-multiplatform (KMP) library for iOS / Android. I have written some unit tests for JVM, for which I use MockK to create spies and mocks, but MockK doesn't support Kotlin native fully yet.
Therefore, I was wondering how others…

Abel
- 1,337
- 1
- 8
- 16
14
votes
1 answer
What's the different between native-mt and normal kotlin coroutine lib?
When we use coroutine, we can either have the normal kotlin coroutine or the native-mt version.
i.e.
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
or
implementation…

Elye
- 53,639
- 54
- 212
- 474