• spierce7

    spierce7

    1 year ago
    Can
    kotlin("multiplatform")
    projects depend on other gradle modules in the repo that are
    kotlin("jvm")
    ? I thought they could, but I’m seeing problems
    spierce7
    c
    +1
    3 replies
    Copy to Clipboard
  • Shan

    Shan

    1 year ago
    Hello all. Is there a way to change the project name kmpp uses as the artifact ID for maven publishing? I have a format like this
    root
    |___core
         |__src
             |__commonMain
             |__jvmMain //etc
         |__build.gradle.kts
    |___otherModule
         |__src
            |__commonMain
            |__jvmMain //ec
         |__ build.gradle.kts
    |__settings.gradle.kts //root project name set here
    |__gradle.properties
    It's defaulting to
    core-jvm
    /
    core-metadata
    etc. right now for the artifact ID, but i'd like all of the generated artifact IDs to be
    foo-jvm
    /
    foo-metadata
    etc. I have been setting them all individually but feel like there might be a better way to just set that parameter once somewhere in the build script.
    Shan
    a
    2 replies
    Copy to Clipboard
  • Shan

    Shan

    1 year ago
    Err looks like the separate
    metadata
    default artifact was removed in Kotlin 1.4.20, but I'm still seeing it when listing out the default publication names.
    publishing {
        publications.withType<MavenPublication>().names // [jvm, kotlinMultiplatform, metadata]
    }
    Should I just manually set it to not publish the
    metadata
    artifact, or will it be ignored during the publish task?
    Shan
    1 replies
    Copy to Clipboard
  • BollywoodVillain

    BollywoodVillain

    1 year ago
    Kotlin Multiplatform fails on iOS while calling Ktor suspend functions. The error is
    kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen
    . It works fine on Android and gets the network data without issues. I created a brand new MPP project using Android Studio MPP template and added the Ktor network code from Ktor-sample/client-mpp repo. What could be the problem? The complete project is on Github at: https://github.com/samkhawase/Kotlin_MPP_Demo. I’m using ktor
    1.4.2
    , Kotlin
    1.4
    , Kotlin plugin
    1.4.20-release-Studio4.1.1
    , and KMM plugin
    0.2.0-release-65-Studio4.1
    . Here’s a snapshot of my
    sourceSets
    from
    build.gradle.kt
    (😒hared)
    val ktor_version = "1.4.2"
        sourceSets {
            val commonMain by getting {
                dependencies {
                    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
                    implementation("io.ktor:ktor-client-core:$ktor_version")
                    implementation("io.ktor:ktor-client-serialization:$ktor_version")
                }
            }
            val commonTest by getting {
                dependencies {
                    //... 
                    implementation("io.ktor:ktor-client-core:$ktor_version")
                }
            }
            val androidMain by getting {
                dependencies {
                    //... 
                    implementation("io.ktor:ktor-client-android:$ktor_version")
                    implementation("io.ktor:ktor-client-serialization-jvm:$ktor_version")
                }
            }
            val androidTest by getting {
                dependencies {
                    //... 
                    implementation("io.ktor:ktor-client-android:$ktor_version")
                }
            }
            val iosMain by getting {
                dependencies {
                    implementation("io.ktor:ktor-client-ios:$ktor_version")
                    implementation("io.ktor:ktor-client-serialization:$ktor_version")
                }
            }
            val iosTest by getting {
                dependencies {
                    implementation("io.ktor:ktor-client-ios:$ktor_version")
                    implementation("io.ktor:ktor-client-serialization:$ktor_version")
                }
            }
        }
    Here’s the failing Swift code
    func getLocations() {
            let apiService = ApiService()
            apiService.about { (htmlString) in
                print("🦋 htmlString:\n \(htmlString)")
            }
    }
    
    struct ContentView: View {
        var body: some View {
            Text(greet()).onAppear {
                print("isMainThread: \(Thread.isMainThread)")
                getLocations()
            }
        }
    }
    Here’s the complete stacktrace from the iOS app.
    BollywoodVillain
    Cicero
    +3
    59 replies
    Copy to Clipboard
  • BollywoodVillain

    BollywoodVillain

    1 year ago
    isMainThread: true
    Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
    It is considered unexpected and unhandled instead. Program will be terminated.
    Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen com.berlin.kmm_demo.shared.ApiService@2a37878
        at 0   shared                              0x0000000100c192dd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
        at 1   shared                              0x0000000100c121cb kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
        at 2   shared                              0x0000000100c1238b kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
        at 3   shared                              0x0000000100c4793b kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
        at 4   shared                              0x0000000100c491f2 ThrowInvalidMutabilityException + 690 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:92:11)
        at 5   shared                              0x0000000100d4136c MutationCheck + 108
        at 6   shared                              0x0000000100bb7ce7 kfun:com.berlin.kmm_demo.shared.ApiService#<init>(){} + 455
        at 7   shared                              0x0000000100bbc743 objc2kotlin + 163
        at 8   iosApp                              0x0000000100ae655f $sSo16SharedApiServiceCABycfC + 31
        at 9   iosApp                              0x0000000100ae6467 $s6iosApp12getLocationsyyF + 39 (/Users/skhawase/skunkworks/KMM_Demo/iosApp/iosApp/ContentView.swift:13:1)
        at 10  iosApp                              0x0000000100ae6eaa $s6iosApp11ContentViewV4bodyQrvgyycfU_ + 442 (/Users/skhawase/skunkworks/KMM_Demo/iosApp/iosApp/ContentView.swift:20:9)
        at 11  SwiftUI                             0x00007fff55f13d0c $sIeg_ytIegr_TR + 12
        at 12  SwiftUI                             0x00007fff55e22b01 $sIeg_ytIegr_TRTA + 17
        at 13  SwiftUI                             0x00007fff55f13d2c $sytIegr_Ieg_TR + 12
        at 14  SwiftUI                             0x00007fff55f13d0c $sIeg_ytIegr_TR + 12
        at 15  SwiftUI                             0x00007fff55e22b01 $sIeg_ytIegr_TRTA + 17
        at 16  SwiftUI                             0x00007fff55e22c09 $sIeg_ytIegr_TRTA.8 + 9
        at 17  SwiftUI                             0x00007fff5636e239 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 1657
        at 18  SwiftUI                             0x00007fff5636d2f7 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 343
        at 19  SwiftUI                             0x00007fff564d4e41 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 241
        at 20  SwiftUI                             0x00007fff564d4e65 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
        at 21  UIKitCore                           0x00007fff24bcd686 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2874
        at 22  QuartzCore                          0x00007fff27a5ae67 -[CALayer layoutSublayers] + 258
        at 23  QuartzCore                          0x00007fff27a61319 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
        at 24  QuartzCore                          0x00007fff27a6d071 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
        at 25  QuartzCore                          0x00007fff279ad158 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
        at 26  QuartzCore                          0x00007fff279e3ef3 _ZN2CA11Transaction6commitEv + 783
        at 27  UIKitCore                           0x00007fff2468ab96 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
        at 28  CoreFoundation                      0x00007fff203a85db __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
        at 29  CoreFoundation                      0x00007fff203a79ef __CFRunLoopDoBlocks + 434
    
    Process finished with exit code 0
    BollywoodVillain
    m
    2 replies
    Copy to Clipboard
  • a

    Amritansh

    1 year ago
    I am getting
    Execution failed for task ':shared:cinteropAFNetworkingIosArm64'.> Process 'command '/Applications/Android Studio 2.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
    when I am adding a pod
    cocoapods {
        pod(name ="AFNetworking", version = "~> 4.0.1")
    }
    Anyone seen this before?
    a
    1 replies
    Copy to Clipboard
  • František Hlinka

    František Hlinka

    1 year ago
    Hey guys! We’re using the
    ios()
    target shortcut inside the
    kotlin {…}
    block in
    build.gradle.kts
    to create iOS targets for simulator and device and use the same
    iosMain
    source set. However, the dependencies of the iOS target do not get resolved correctly in the IDE (specifically speaking, the
    Platform
    object, or SQLDelight’s
    NativeSqliteDriver
    ). If hierarchical project structure is disabled - e.g.
    gradle.properties
    does not include
    kotlin.mpp.enableGranularSourceSetsMetadata=true
    kotlin.native.enableDependencyPropagation=false
    , then the project builds anyway even if the IDE can’t resolve the classes. If I add those two lines, the build fails too. This is happening on Kotlin 1.4.10 and 1.4.20. Does anyone know what’s the problem or where should I open an issue? Thanks lots!
    František Hlinka
    r
    +1
    6 replies
    Copy to Clipboard
  • n

    Nikolay Kasyanov

    1 year ago
    Hey folks, I have a feeling this must be a known issue. Here’s what happens: I have a KMP project and as soon as I have built something, IDEA (or Android Studio) starts using built artifacts (jar, class files) for code highlighting and navigation in the editor. For example, it starts falsely reporting some imports as unreachable because of classes being internal (although actual build works flawlessly, meaning internal is just fine). When you cmd-click the import, it shows a decompiled version of it instead of the source code. It definitely happens with types from
    commonMain
    when imported in files residing in
    jvmTest
    . Doing
    ./gradlew clean
    solves the problem (editor navigation starts using source code, red highlighting of imports goes away) until next build. IDEA CE 2020.3 beta or 2020.2.4, Kotlin plugin 1.4.20.
    n
    Cicero
    +1
    20 replies
    Copy to Clipboard
  • tjohnn

    tjohnn

    1 year ago
    Hey guys, any advice on mocking in commonTest? I tried mockk without success
    tjohnn
    k
    3 replies
    Copy to Clipboard
  • Vinod Rai

    Vinod Rai

    1 year ago
    Hey, Can anyone please guide or provide any link here to generate a native Universal framework with minimum size? I am generating a Universal framework and it's working perfectly but it's increasing IPA size drastically. Here is my build.gradle.kts file.
    import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
    
    plugins {
        kotlin("multiplatform")
        kotlin("plugin.serialization")
        id("com.squareup.sqldelight")
    }
    
    kotlin {
        val iosX64 = iosX64("ios")
        val iosArm64 = iosArm64("iosArm64")
        val iosArm32 = iosArm32("iosArm32")
        val frameworkName = "EmtCore"
        configure(listOf(iosX64, iosArm64, iosArm32)) {
            binaries.framework {
                baseName = frameworkName
            }
        }
        sqldelight {
            database("EmtCoreDatabase") {
                packageName = "com.emt_core.db"
            }
        }
        jvm("android")
    
        sourceSets["commonMain"].dependencies {
            implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
            implementation("io.ktor:ktor-client-core:1.4.1")
            implementation("io.ktor:ktor-client-json:1.4.1")
            implementation("com.russhwolf:multiplatform-settings-no-arg:0.6.1")
            implementation("io.ktor:ktor-client-serialization:1.4.1")
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt-2")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-rc")
            implementation("com.soywiz.korlibs.klock:klock:1.12.0")
            implementation("io.ktor:ktor-client-logging:1.4.1")
            implementation("com.squareup.sqldelight:runtime:1.4.3")
        }
    
        sourceSets["androidMain"].dependencies {
            implementation("org.jetbrains.kotlin:kotlin-stdlib")
            implementation("io.ktor:ktor-client-android:1.4.1")
            //implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-rc")
            implementation("io.ktor:ktor-client-okhttp:1.4.1")
            api("io.ktor:ktor-client-logging-jvm:1.4.1")
            implementation("io.ktor:ktor-client-json-jvm:1.4.1")
            implementation("io.ktor:ktor-client-serialization-jvm:1.4.1")
            implementation("com.squareup.okhttp3:logging-interceptor:4.4.1")
            implementation("com.squareup.sqldelight:android-driver:1.4.3")
    
        }
    
        sourceSets["iosMain"].dependencies {
            implementation("io.ktor:ktor-client-ios:1.4.1")
            //implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-rc")
            implementation("io.ktor:ktor-client-json-native:1.3.2")
            api("io.ktor:ktor-client-logging-native:1.3.2")
            implementation("io.ktor:ktor-client-serialization-iosx64:1.4.1")
            //implementation("io.ktor:ktor-client-serialization-iosarm64:1.4.0")
            implementation("com.squareup.sqldelight:native-driver:1.4.3")
        }
    
        sourceSets["iosArm64Main"].dependencies {
            implementation("io.ktor:ktor-client-ios:1.4.1")
            //implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-rc")
            implementation("io.ktor:ktor-client-json-native:1.3.2")
            api("io.ktor:ktor-client-logging-native:1.3.2")
            implementation("io.ktor:ktor-client-serialization-iosarm64:1.4.1")
            //implementation("io.ktor:ktor-client-serialization-iosarm64:1.4.0")
            implementation("com.squareup.sqldelight:native-driver:1.4.3")
        }
    
        sourceSets["iosArm32Main"].dependencies {
            implementation("io.ktor:ktor-client-ios:1.4.1")
            //implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-rc")
            implementation("io.ktor:ktor-client-json-native:1.3.2")
            api("io.ktor:ktor-client-logging-native:1.3.2")
            implementation("io.ktor:ktor-client-serialization-iosarm32:1.4.1")
            //implementation("io.ktor:ktor-client-serialization-iosarm64:1.4.0")
            implementation("com.squareup.sqldelight:native-driver:1.4.3")
        }
    
        val debugFatFramework by tasks.creating(org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask::class) {
            baseName = frameworkName
            from(
               iosArm32.binaries.getFramework("debug"),
                iosArm64.binaries.getFramework("debug"),
                iosX64.binaries.getFramework("debug")
            )
            destinationDir = buildDir.resolve("fat-framework/debug")
            group = "Universal framework"
            description = "Builds a debug universal (fat) framework"
        }
    
        val releaseFatFramework by tasks.creating(org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask::class) {
            baseName = frameworkName
            from(
                iosArm32.binaries.getFramework("release"),
                iosArm64.binaries.getFramework("release")
            )
            destinationDir = buildDir.resolve("fat-framework/release")
            group = "Universal framework"
            description = "Builds a release universal (fat) framework"
        }
    
        val zipDebugFatFramework by tasks.creating(Zip::class) {
            dependsOn(debugFatFramework)
            from(debugFatFramework)
           // from("LICENSE.md")
        }
    
        val zipReleaseFatFramework by tasks.creating(Zip::class) {
            dependsOn(releaseFatFramework)
            from(releaseFatFramework)
            //from("LICENSE.md")
        }
    }
    Vinod Rai
    Kuba Petržílka
    +1
    3 replies
    Copy to Clipboard