Ryan Simon

    Ryan Simon

    2 years ago
    how should i be configuring my build script to use generics? i tried following the documentation and digging into the PR that added generics support but i don't know if i'm doing it right
    tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xobjc-generics")
        }
    }
    I tried setting it up with the
    kotlin {
       ios {
            binaries.framework {
                freeCompilerArgs = freeCompilerArgs + "-Xobjc-generics"
            }
        }
    }
    And that was complaining about the name being the same
    Kris Wong

    Kris Wong

    2 years ago
    freeCompilerArgs.add("-Xobjc-generics")
    Ryan Simon

    Ryan Simon

    2 years ago
    @Kris Wong huh okay, and where do I add that in my build file?
    Kris Wong

    Kris Wong

    2 years ago
    in your framework binary's config block
    Ryan Simon

    Ryan Simon

    2 years ago
    @Kris Wong I hate to be that guy, but do you happen to have an example of what that looks like? I'm super noob on configuring KMP. Thanks for your help
    Kris Wong

    Kris Wong

    2 years ago
    your second example is what I am talking about
    Ryan Simon

    Ryan Simon

    2 years ago
    @Kris Wong ah gotcha. i get this error when i try it
    freeCompilerArgs.add("-Xobjc-generics")
                                            ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                                                public inline fun DependencyHandler.add(configuration: String, dependencyNotation: String, dependencyConfiguration: ExternalModuleDependency.() -> Unit)
    i think that the
    freeCompilerArgs
    at that point is a non-mutable
    List
    ios {
            binaries.framework {
                freeCompilerArgs.add("-Xobjc-generics")
            }
        }
    Kris Wong

    Kris Wong

    2 years ago
    ah, then += operator should do the trick
    Ryan Simon

    Ryan Simon

    2 years ago
    right, okay. then it looks like this
    ios {
            binaries.framework("Generics") {
                freeCompilerArgs = freeCompilerArgs + "-Xobjc-generics"
            }
        }
    i had to add the "Generics" name otherwise it wouldn't build
    Kris Wong

    Kris Wong

    2 years ago
    that's a problem because it's going to create 2 different frameworks
    are you using the cocoapods plugin?
    Ryan Simon

    Ryan Simon

    2 years ago
    Yeah I am
    looks like this @Kris Wong
    cocoapods {
            summary = "Common library for the KaMP starter kit"
            homepage = "<https://github.com/touchlab/KaMPStarter>"
        }
    Kris Wong

    Kris Wong

    2 years ago
    then you need to modify the framework it creates for you rather than creating a new one
    Ryan Simon

    Ryan Simon

    2 years ago
    ohhh, how does one do that? 😮
    I looked through the docs for the plug-in but couldn't find anything on how to configure it @Kris Wong
    alternatively you could use tasks.withType<KotlinNativeLink>().configureEach { ...
    Ryan Simon

    Ryan Simon

    2 years ago
    huh okay, thanks for your help. much appreciated i've been studying the kotlinconf gradle build file. looks like that might be a good option too https://github.com/JetBrains/kotlinconf-app/blob/master/common/build.gradle.kts
    Kris Wong

    Kris Wong

    2 years ago
    looks like there's a bunch of ways
    Ryan Simon

    Ryan Simon

    2 years ago
    yeah
    @Kris Wong this worked for me and solved for my generics issue
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().configureEach {
        this.binary.freeCompilerArgs += "-Xobjc-generics"
    }
    Kris Wong

    Kris Wong

    2 years ago
    technically replace binary with kotlinOptions
    that's basically going link task -> binary -> link task -> kotlinOptions -> freeCompilerArgs
    not a big deal
    Ryan Simon

    Ryan Simon

    2 years ago
    ah cool, good to know
    thanks