https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Samuel Michael

09/18/2020, 1:53 PM
Trying to find the easiest way to use a KMM library as a dependency for separate iOS, Android, and possibly Web, any suggestions?
d

Derek Ellis

09/19/2020, 3:36 PM
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
s

Samuel Michael

09/19/2020, 3:37 PM
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
d

Derek Ellis

09/20/2020, 5:21 PM
I would combine them into one big project folder. That's the general convention when it comes to Android/iOS apps with KMM.
s

Samuel Michael

09/20/2020, 5:22 PM
Ok yes I went that way, now trying to import the shared module into iOS having some problem
d

Derek Ellis

09/20/2020, 5:22 PM
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
s

Samuel Michael

09/20/2020, 5:22 PM
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
d

Derek Ellis

09/20/2020, 5:23 PM
Are you using the cocoapods plugin?
s

Samuel Michael

09/20/2020, 5:23 PM
Nope didn’t hear about that
I mean know a little about cocoapods, but which plugin is that?
d

Derek Ellis

09/20/2020, 5:23 PM
I would recommend using that. Makes it really easy to set up the shared Kotlin module as a pod dependency in your iOS app
s

Samuel Michael

09/20/2020, 5:24 PM
cool so is that instead of the pack for xcode gradle task?
d

Derek Ellis

09/20/2020, 5:24 PM
Yes
s

Samuel Michael

09/20/2020, 5:25 PM
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
d

Derek Ellis

09/20/2020, 5:28 PM
I usually just run it from within xcode rather than the terminal
s

Samuel Michael

09/20/2020, 5:29 PM
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
d

Derek Ellis

09/20/2020, 5:29 PM
Have you tried the new KMM plugin for AS?
s

Samuel Michael

09/20/2020, 5:30 PM
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
d

Derek Ellis

09/20/2020, 5:30 PM
Oh huh, I see
s

Samuel Michael

09/20/2020, 5:30 PM
d

Derek Ellis

09/20/2020, 5:31 PM
that is kind of odd since with the cocoapods plugin you don't really have a choice but to use the workspace
s

Samuel Michael

09/20/2020, 5:31 PM
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
Copy code
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
2 Views