Questions tagged [kotlin-multiplatform]
Refers to Kotlin Multiplatform projects, aimed to share codebase between JVM, JS, Android, and Native
1,864
questions
102
votes
10
answers
166k
views
Flutter & Android: Your build is currently configured to use Java 17.0.2 and Gradle 7.0.2
I got this on my android part of Flutter.
Unsupported Java.
Your build is currently configured to use Java 17.0.2 and Gradle 7.0.2.
Possible solution:
- Open Gradle wrapper settings, change `...
86
votes
2
answers
126k
views
Check your module classpath for missing or conflicting dependencies [closed]
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 &...
36
votes
1
answer
6k
views
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
sourceSets[&...
25
votes
3
answers
42k
views
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")
...
25
votes
0
answers
2k
views
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, ...
22
votes
2
answers
5k
views
@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()
...
20
votes
5
answers
9k
views
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: ...
20
votes
1
answer
6k
views
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 ...
20
votes
4
answers
22k
views
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<HttpResponse>(url) {
body = TextContent("""{"a":1,"b":2}""", ContentType....
19
votes
3
answers
10k
views
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:
...
19
votes
3
answers
8k
views
Is there a way to use Firebase (Authentication) with Kotlin Multiplatform?
I have a project which uses Firebase Authentication in Android. It works well and I want to port the same project to an iOS App using code sharing with Kotlin Multiplatform.
I initially thought I ...
17
votes
4
answers
4k
views
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-...
17
votes
1
answer
1k
views
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 ...
16
votes
2
answers
5k
views
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 ...
16
votes
9
answers
20k
views
"No transformation found: class io.ktor.utils.io.ByteChannelNative" error using Ktor
I'm trying to fetch and deserialize some data that is being hosted on github.
{
"Meals": [
{
"id": "1598044e-5259-11e9-8647-d663bd870b02",
"name&...
16
votes
2
answers
673
views
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 ...
16
votes
0
answers
5k
views
SourceSet with name 'jvmMain' not found
I'm trying to run kotlin multiplatform project with jvm and js source sets but am getting the following error:
FAILURE: Build failed with an exception.
* Where:
Initialization script '/private/var/...
15
votes
3
answers
9k
views
File IO with Kotlin multiplatform
I would like to do some basic filesystem operations on mingwX64 Windows (and possibly other platforms): open, close, read, rename, get metadata, list files in a directory.
I have found one project ...
15
votes
5
answers
4k
views
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 ...
15
votes
1
answer
3k
views
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 '...
15
votes
1
answer
5k
views
How to fix 'The feature "multi platform projects" is experimental and should be enabled explicitly' warning in IntelliJ IDEA
Whenever I write an expect function in IntelliJ IDEA, I get the following warning:
The feature "multi platform projects" is experimental and should be enabled explicitly
Where can enable ...
14
votes
5
answers
6k
views
How to configure an iOS Application for Kotlin Multiplatform in Android Studio?
I want to add a Run/Debug Configuration for an iOS Application for a Kotlin Multiplatform Mobile application in Android Studio 4.1.2. However, there seems to be a problem with the configuration for ...
13
votes
8
answers
11k
views
KMM project setup with cocoaPods fails on first compile
I created a new KMM project and selected Cocoapods for the iOS framework distribution and as soon as it finished building it threw the following error:
Executing of 'pod install' failed with code 1.
...
13
votes
2
answers
8k
views
Kotlin Multiplatform : Plugin [id: 'com.android.library'] was not found
I am trying to set up Android Library via Kotlin Multiplatform Library.
I am getting error:
Plugin [id: 'com.android.library'] was not found in any of the following sources:
Please help me by ...
13
votes
2
answers
6k
views
Spaces in test method names when targeting multiplatform
I really love the ability of Kotlin to add spaces to method names, which is a well-documented approach commonly used to make test names more readable:
In tests (and only in tests), it's acceptable ...
13
votes
2
answers
3k
views
Kotlin Multiplatform Mobile: How to handle errors (network, db, etc.) in iOS?
I have this function that makes a network request and writes results to SQLDelight database:
@Throws(Exception::class)
suspend fun updateData()
In iOS project in Xcode I see that this function is ...
13
votes
1
answer
832
views
How to read file with okio inside commanMain module in a Kotlin Multiplatform Project?
I am trying to read/write files in the commonMain module.
I created a new Kotlin Multiplatform App for Android and iOS using the Android Studio Wizard. (New -> New Project ... -> Koltin ...
13
votes
0
answers
359
views
Kotlin multiplatform 'Go to declaration' goes to decompiled code
When using using Android Studio's 'Go to declaration' feature (cmd + click), a decompiled source is shown, when though the source is in my project. The kotlin MP source is in another module. I can ...
13
votes
2
answers
11k
views
Kotlin Multiplatform Mobile unable to run on iOS: Execution failed for task ':shared:compileKotlinIosX64'
I have created fresh project(Hello World) in KMM followed by their official website. In android it works smooth but when I am trying to run in XCode it's giving errors because of which I am unable to ...
12
votes
6
answers
15k
views
Kotlin Multi Platform default project error running iOs App: could not resolve com.android.tools.build:gradle:7.4.0-rc01
I created a default KMP project, and changed nothing. It runs fine on android, but when I try to run it on iOS it tells me that it cant find the gradle plugin:
A problem occurred configuring root ...
12
votes
3
answers
3k
views
Kotlin multiplatform: Accessing build variables in code
I'm working on a Kotlin Multiplatform project which is an SDK providing functionality for iOS & Android applications.
In our build.gradle.kts we have a couple of variables that we would like to ...
12
votes
3
answers
6k
views
Use Gradle sub-projects with Kotlin multiplatform
I'm using Kotlin multi-platform (JVM & JS), which in IDEA creates three projects: demo, demo-js and demo-jvm.
I would like to split the common code into more subprojects/submodules. Let's say I ...
12
votes
4
answers
4k
views
Is there multiplatform lock in Kotlin?
What multiplatform Lock or synchronization approach should be used in multiplatform Kotlin code? Previously in Java code i used synchronized and i can see synchronized in Kotlin too. However it's ...
12
votes
4
answers
7k
views
Is there a way in Kotlin Multiplatform to format a float to a number of decimal places?
Most of the answers use Java (e.g. String.format) to get the job done, but I need a way to do this purely with Kotlin to support multiplatform programming.
This means not using java.* standard ...
12
votes
3
answers
3k
views
Kotlin Multiplatform Project Unit Test Issue
Today I just updated my Android Studio to
Android Studio 3.5.2
Build #AI-191.8026.42.35.5977832, built on October 31, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM ...
11
votes
4
answers
4k
views
Cannot locate tasks that match ':composeApp:compileJava' as task 'compileJava' is ambiguous in project ':composeApp'
Cannot locate tasks that match ':composeApp:compileJava' as task 'compileJava' is ambiguous in project ':composeApp'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac'...
11
votes
2
answers
3k
views
How to determine build type in kotlin-multiplatform project
I’m working on a multiplaform project, iOS and JVM (I’m not targeting Android directly). Depending on the build type (debug or release) I want to configure the logging level (i.e. to print only errors ...
11
votes
4
answers
13k
views
Ktor: Serialize/Deserialize JSON with List as root in Multiplatform
How can we use kotlin.serialize with Ktor's HttpClient to deserialize/serialize JSON with lists as root? I am creating the HttpClient as follows:
HttpClient {
install(JsonFeature) {
...
11
votes
2
answers
9k
views
Gradle sync failed: Unsupported method: KotlinPlatformContainer.supports()
I just updated Android Studio to the latest version 3.5.1 and I know get the following error:
Gradle sync failed: Unsupported method:
KotlinPlatformContainer.supports(). The version of Gradle you ...
11
votes
2
answers
5k
views
Execution failed for task ':shared:podInstall'
I am very new to KMM (Kotlin Multiplatform Mobile) and iOS development (including CocoaPods). I have come across the following build error in Android Studio.
Execution failed for task ':shared:...
11
votes
6
answers
5k
views
Kotlin MPP expect / actual with different signatures
I have a manager class that has an Android and iOS impl (from a 3rd party lib). "ex. MyManagerImpl()". To construct the 3rd party manager, iOS does not require a Context but Android does. I ...
11
votes
3
answers
2k
views
Kotlin Multiplatform library for iOS with bitcode
we use Kotlin to share a library between Android and iOS.
We set up everything, but on iOS i need Bitcode enabled.
After a research I found solution:
kotlin {
targets {
fromPreset(presets.jvm, '...
11
votes
1
answer
2k
views
Multi-platform InputStream Alternative in Kotlin?
I’m looking for a multi-platform alternative to input streams. My concrete task is to fetch an encrypted file from a remote server via https and decrypt it on demand.
In Java land I would an ...
11
votes
1
answer
5k
views
Multiplatform error when building iosApp: Command PhaseScriptExecution failed with a nonzero exit code
I am working on a multiplatform app in Kotlin on Android Studio and when I try to run the app to an iOS simulator, I get this error:
The following build commands failed:
PhaseScriptExecution [CP-User]...
11
votes
1
answer
3k
views
How to share Java code between Android and JVM targets (with Kotlin Multiplatform)?
I am trying to share Java code between Android and JVM targets using Kotlin Multiplatform feature (sample project: https://github.com/dmitrykolesnikovich/accessJavaCode-issue)
Simply saying, ":...
11
votes
1
answer
6k
views
How to do Unit Testing in Kotlin/Native Multiplatform?
I have follow the tutorial of https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html and I wanted to Unit testing the commonTest I created in the SharedModule.
Things I tried:
I had tried ...