Have a quick question. If i have a KMM project, i...
# multiplatform
m
Have a quick question. If i have a KMM project, it’s making me declare either/or/both iosArm64 or iosX64. However, both projects would probably have some common source code. I’m not quite sure how to configure my project for shared source code between iOS architectures. Any pointers? I tried adding an iOS common source set:
Copy code
val iosCommon by creating
val iosArm64Main by getting {
    dependsOn(iosCommon)
}
But it still fails compilation when i move an actual object implementation into iosCommon instead of iOSArm64main
x
Hi, you can create a combined source set like this.
Copy code
kotlin {
  val macosX64 = macosX64()
  val macosArm64 = macosArm64()
  val iosArm64 = iosArm64()
  val iosX64 = iosX64()
  val iosSimulatorArm64 = iosSimulatorArm64()
  val watchosArm32 = watchosArm32()
  val watchosArm64 = watchosArm64()
  val watchosX64 = watchosX64()
  val watchosSimulatorArm64 = watchosSimulatorArm64()
  val tvosArm64 = tvosArm64()
  val tvosX64 = tvosX64()
  val tvosSimulatorArm64 = tvosSimulatorArm64()
  val appleTargets = listOf(
    macosX64, macosArm64,
    iosArm64, iosX64, iosSimulatorArm64,
    watchosArm32, watchosArm64, watchosX64,
    watchosSimulatorArm64,
    tvosArm64, tvosX64, tvosSimulatorArm64,
  )

  appleTargets.forEach { target ->
    with(target) {
      binaries {
        framework {
          baseName = "Whatever"
        }
      }
    }
  }
  
  sourceSets {
    val appleMain by creating {
      dependsOn(commonMain)
    }
    val appleTest by creating

    appleTargets.forEach{ target ->
      getByName("${target.targetName}Main") { dependsOn(appleMain) }
      getByName("${target.targetName}Test") { dependsOn(appleTest) }
    }
  }
}
m
I tried something like this @xxfast . It was a bit simpler in that i directly declared the dependencies rather than iterating through a list, but it has the same net effect. The issue i have is that this common ios folder can’t find my cocoapods.