• jared

    jared

    1 year ago
    I am using
    kotlinx.coroutines
    1.3.9-native-mt-2
    and Ktor
    1.4.2
    in a multiplatform library for sharing networking between iOS and Android. I am confused over Ktor and background threads. I am using the
    Main
    dispatcher and I can’t tell if the network request is running on the main thread or a background thread. Does Ktor handle running a single background thread for me?
    jared
    John O'Reilly
    +1
    21 replies
    Copy to Clipboard
  • Cicero

    Cicero

    1 year ago
    A small weird question, have you ever stumbled into adding a library and then suddenly your project is not recognized anymore as a Kotlin project? It took me a while to realize it was because of a library, ktor-client-gson specifically, and, when working with android, I didn't really stumbled on this before
    Cicero
    c
    2 replies
    Copy to Clipboard
  • Nikita Khlebushkin

    Nikita Khlebushkin

    1 year ago
    Hello! I have a KMM library created and developed from KMM template less than a month ago. It has the following structure:
    mobile-shared [SharedLogic]
    |____ ModuleShared
    |____ TestAndroidApp
    |____ TestIosApp
    I can build and compile KMM library, assemble .jar, Cocoapods - no problem here. Lately I've been trying to add this project as a module dependency to an Android project, which used to have the following structure:
    MyApp
    |____ app
    and now has the following structure:
    MyApp
    |____ app
    |____ mobile-shared [SharedLogic]
    |____|____ ModuleShared
    |____|____ TestAndroidApp
    |____|____ TestIosApp
    How I was trying to do it: Option 1: MyApp/settings.gradle.kts:
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            jcenter()
            mavenCentral()
        }
        resolutionStrategy {
            eachPlugin {
                if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
                    useModule("com.android.tools.build:gradle:4.0.1")
                }
            }
        }
    }
    
    include(":app")
    include(":SharedLogic")
    project(":SharedLogic").projectDir = File("mobile-shared")
    include(":SharedLogic:ModuleShared")
    MyApp/app/build.gradle.kts:
    ...
    android {
        dependencies {
            implementation(project(":SharedLogic:ModuleShared"))
    Option 2: MyApp/settings.gradle.kts:
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            jcenter()
            mavenCentral()
        }
        resolutionStrategy {
            eachPlugin {
                if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
                    useModule("com.android.tools.build:gradle:4.0.1")
                }
            }
        }
    }
    
    include(":app")
    include(":ModuleShared")
    project(":ModuleShared").projectDir = File("mobile-shared/ModuleShared")
    MyApp/app/build.gradle.kts:
    ...
    android {
        dependencies {
            implementation(project(":ModuleShared"))
    Error I encounter:
    A problem occurred configuring project ':SharedLogic:ModuleShared'.
    * Where:
    Build file '/home/xlebnick/projects/MyApp/mobile-shared/ModuleShared/build.gradle.kts' line: 40
    
    * What went wrong:
    This version of the kotlin-serialization Gradle plugin is built for a newer Kotlin version. Please use an older version of kotlin-serialization or upgrade the Kotlin Gradle plugin version to make them match.
    In ModuleShared/build.gradle.kts:
    plugins {
        kotlin("plugin.serialization") version "1.4.10"
    }
    In mobile-shared/build.gradle.kts:
    buildscript {
        repositories {
            gradlePluginPortal()
            jcenter()
            google()
            mavenCentral()
        }
        dependencies {
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
            classpath("com.android.tools.build:gradle:4.1.0")
        }
    }
    And in MyApp/build.gradle.kts:
    uildscript {
        apply(from = "versions.gradle.kts")
        val kotlinVersion: String by extra // 1.4.10
        val rootClasspath: List<String> by extra
    
        repositories {
            mavenCentral()
            google()
            jcenter()
            maven("<https://plugins.gradle.org/m2/>")
            maven("<https://maven.fabric.io/public>")
        }
    
        dependencies {
            classpath(kotlin("gradle-plugin", version = kotlinVersion))
            for (rc in rootClasspath) {
                classpath(rc)
            }
        }
    }
    What am I doing wrong? P.S. Found this issue, but it doesn't help at all
    Nikita Khlebushkin
    1 replies
    Copy to Clipboard
  • Philip Dukhov

    Philip Dukhov

    1 year ago
    Hi! I have a multiplatform module containing a server, with one kotlin multiplatform dependency module . Running it from main function with play button produces following error:
    Error: Could not find or load main class com.well.server.ApplicationKt
    I’ve found a solution to run it, using following task:
    task<JavaExec>("run") {
    main = "com.well.server.ApplicationKt"
    val jvm by kotlin.targets.getting
    val main: KotlinCompilation<KotlinCommonOptions> by jvm.compilations
    val runtimeDependencies = (main as KotlinCompilationToRunnableFiles<KotlinCommonOptions>).runtimeDependencyFiles
    classpath = files(main.output.allOutputs, runtimeDependencies)
    }
    One of the minuses - I can’t debug server and run an other module, because server starts running as part of task, and task progress remains 92 until I abort it. Is there a better solution? But the main goal right now is to deploy the server. Following the official guide, I tried this code:
    tasks.create("stage") {
    dependsOn(tasks.getByName("installDist"))
    }
    application {
    mainClassName = "ApplicationKt"
    }
    distributions {
    main {
    contents {
    from("$buildDir/libs") {
    rename("${rootProject.name}-jvm", rootProject.name)
    into("lib")
    }
    }
    }
    }
    tasks.getByName<JavaExec>("run") {
    `classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by
    jvmJar
    can be found and served`
    }
    But
    ./gradlew :server:run
    returns
    Could not find or load main class ApplicationKt
    error, and
    :server:jvmJar
    finishes without errors but doesn’t seems to produce the output
    Philip Dukhov
    Big Chungus
    +1
    36 replies
    Copy to Clipboard
  • a

    Amritansh

    1 year ago
    Hello, I am working on a KMM library which requires me to get these values from iOS and Android Devices.  • appVersion • connection type: Wifi or cellular • Carrier • Os version • Device model What will be the best way to approach this? Should I ask them at the time of initialization in the Apps or is there another way to get them internally from the KMM project? Happy to elaborate more if this does not make sense.
    a
    w
    +2
    6 replies
    Copy to Clipboard
  • w

    william

    1 year ago
    has anyone tried using
    kotlin.Result
    in multiplatform? i'm not having any luck using it with
    kotlin {
        targets.all {
            compilations.all {
                kotlinOptions {
                    freeCompilerArgs = freeCompilerArgs + "-Xallow-result-return-type"
                }
            }
        }
    }
    I still get the message saying I can't use result as a return type
    w
    1 replies
    Copy to Clipboard
  • w

    william

    1 year ago
    alternatively does anyone know of multiplatform Result libraries? i haven't been able to find one supporting jvm and ios
    w
    z
    8 replies
    Copy to Clipboard
  • Rengu N

    Rengu N

    1 year ago
    Hello Team - Do anyone know how to make build variants for KMP especially for native iOS
    Rengu N
    1 replies
    Copy to Clipboard
  • Sergio Casero

    Sergio Casero

    1 year ago
    Hello guys, I have a kmp module with JVM target, the problem is that the IDE doesn't recognize it in one of my modules, it doesn't have any sense because, in fact, If I compile the project by manual putting the imports, it works perfectly, but the IDE doesn't recognize it, any solutions? I've included the dependency with
    implementation(project(":accesscontrol"))
    This is my 6th kmp project and I never get this issue. I have 3 JVM modules and works on 2 of them perfectly. I've tried cleaning the project, invalidating the cache, restarting the PC... When I execute
    ./gradlew run
    I can see that common related tasks are executed, and I can see the jar inside the build folder
    Sergio Casero
    Mohamed Daif
    5 replies
    Copy to Clipboard
  • Jeremias Nunez

    Jeremias Nunez

    1 year ago
    Hi All! I've successfully integrated a KMP module into an existing iOS app, but I'm having an issue with the difference between the generated Obj-C class name (Prefix+ClassName) and the Swift name (ClassName) of one of my classes. When I try to iterate over an array of such classes I'm getting this error:
    Precondition failed: NSArray element failed to match the Swift Array Element type
    Expected Movie but found SharedMovie: file Swift/ArrayBuffer.swift, line 354
    My Movie class is defined like this:
    @Serializable
    data class Movie(
        val name: String,
        val tone: String,
        val light: String,
        val url: String,
        val order: Int,
        val version: Int
    )
    I found this issue but it doesn't provide any possible solution: https://github.com/JetBrains/kotlin-native/issues/2830
    Jeremias Nunez
    1 replies
    Copy to Clipboard