Thread
#multiplatform
    Samuel Michael

    Samuel Michael

    2 years ago
    Trying to find the easiest way to use a KMM library as a dependency for separate iOS, Android, and possibly Web, any suggestions?
    Derek Ellis

    Derek Ellis

    2 years ago
    What do you mean? You should be able to use any KMP library in a KMP project
    As long as the library supports the appropriate targets
    Samuel Michael

    Samuel Michael

    2 years ago
    Thanks for responding, I mean I am setting up a multiplatform library for a pre-existing iOS app and Android app
    I want to begin extracting shared logic into the library to reduce duplication
    Wondering the best way to access the library and set up the development environment for a demo I am doing
    For example: Should I create a giant folder with both apps and the library all inside and try to reference it from the apps using gradle system and the
    xcodeproj=./iosApp
    Or publish the library to a local or online repo and use it as a dependency that way
    Ideally I want a large team of developers to be able to start moving snippets of code into the library but still having trouble setting up the apps to support that
    Derek Ellis

    Derek Ellis

    2 years ago
    I would combine them into one big project folder. That's the general convention when it comes to Android/iOS apps with KMM.
    Samuel Michael

    Samuel Michael

    2 years ago
    Ok yes I went that way, now trying to import the shared module into iOS having some problem
    Derek Ellis

    Derek Ellis

    2 years ago
    Publishing it as a local/online library and then using it as a dependency would create a pretty inconvenient workflow since you'd have to make changes to the shared logic, and then wait for your changes to be published, before you can then run it
    Samuel Michael

    Samuel Michael

    2 years ago
    Also my iOS app can only be run as a workspace so I am trying to figure that part
    Have to manually run xcodebuild -workspace instead of the default xcodebuild -project
    Derek Ellis

    Derek Ellis

    2 years ago
    Are you using the cocoapods plugin?
    Samuel Michael

    Samuel Michael

    2 years ago
    Nope didn’t hear about that
    I mean know a little about cocoapods, but which plugin is that?
    Derek Ellis

    Derek Ellis

    2 years ago
    I would recommend using that. Makes it really easy to set up the shared Kotlin module as a pod dependency in your iOS app
    Samuel Michael

    Samuel Michael

    2 years ago
    cool so is that instead of the pack for xcode gradle task?
    Derek Ellis

    Derek Ellis

    2 years ago
    Yes
    Samuel Michael

    Samuel Michael

    2 years ago
    Awesome that might be just what I need then 🙏 Thanks
    Weird I ran xcodebuild -workspace in the terminal and it succeeded but the simulator didn’t launch in IDE or externally
    Derek Ellis

    Derek Ellis

    2 years ago
    I usually just run it from within xcode rather than the terminal
    Samuel Michael

    Samuel Michael

    2 years ago
    Created a YouTrack issue to allow user to choose from running KMM iOS app as workspace or project
    Yeah trying to do from Android Studio for fun, but AppCode or Xcode works too I guess
    Derek Ellis

    Derek Ellis

    2 years ago
    Have you tried the new KMM plugin for AS?
    Samuel Michael

    Samuel Michael

    2 years ago
    Yeah that is what I am using but it uses xcodebuild -project as a default
    So I am trying to see If i can edit the terminal command it uses under the hood to use a workspace flag
    Derek Ellis

    Derek Ellis

    2 years ago
    Oh huh, I see
    Samuel Michael

    Samuel Michael

    2 years ago
    Derek Ellis

    Derek Ellis

    2 years ago
    that is kind of odd since with the cocoapods plugin you don't really have a choice but to use the workspace
    Samuel Michael

    Samuel Michael

    2 years ago
    Haha cool You are right I should focus on getting access to the shared library from iOS anyway
    Running iOS simulator in Android Studio is not practical since Swift syntax highlighting doesn’t exist yet
    Hey still trying to add the framework using cocoapods plugin. For some reason it didn’t like when I tried to add the plugin everything turned red.
    Also wanted to ask if you had any idea how to add a podfile to Carthage setup since we use Carthage to manage dependencies
    Or just modify this
    val packForXcode by tasks.creating(Sync::class) {
        group = "build"
        val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
        val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
        val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
        val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
        inputs.property("mode", mode)
        dependsOn(framework.linkTask)
        val targetDir = File(buildDir, "xcode-frameworks")
        from({ framework.outputDirectory })
        into(targetDir)
    }
    pack for Xcode to use find Carthage directory