I'm trying to create a SPM from a module using the...
# multiplatform
l
I'm trying to create a SPM from a module using the multiplatform-swiftpackage plugin. The module contains a simple object file.
Copy code
object Strings {
    val TitleTalks = "Talks"
    val TabTalks = "Talks"
    val TabChannels = "Channel"
    val TabProfile = "Profile"
}
complete build.gradle looks like this
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3"
}

kotlin {
    multiplatformSwiftPackage {
        swiftToolsVersion("5.3")
        targetPlatforms {
            iOS { v("13") }
        }
        packageName("AppStrings")
        outputDirectory(File(projectDir, "spm/strings"))
    }

    android()

    ios {
        binaries {
            framework {
                baseName = "strings"
                isStatic = false
            }
        }
    }

    iosSimulatorArm64 {
        binaries {
            framework {
                baseName = "strings"
                isStatic = false
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(libs.moko.resources.core)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(libs.moko.resources.compose)
            }
        }
        val androidTest by getting

        val iosMain by getting
        val iosTest by getting
        val iosSimulatorArm64Main by getting {
            dependsOn(iosMain)
        }
        val iosSimulatorArm64Test by getting {
            dependsOn(iosTest)
        }
    }
}

android {..}
But I always get the following build error whenever I try accessing
Strings.xx
inside my Swift file
Copy code
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_StringsStrings", referenced from:
      objc-class-ref in ContentView.o
ld: symbol(s) not found for architecture arm64
Any sort of hint will be of great help blob smile
👀 1
x
You are missing the
iosArm64()
target
You'll need something like
Copy code
kotlin {
  ..
  listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64(),
  ).forEach { target ->
    with(target) {
      binaries {
        framework {
          baseName = "strings"
          isStatic = false
        }
      }
    }
  }
  ..
  sourceSets {
    ..
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
      dependsOn(commonMain)
      iosX64Main.dependsOn(this)
      iosArm64Main.dependsOn(this)
      iosSimulatorArm64Main.dependsOn(this)
      dependencies {
        implementation(Ktor.clientIos)
        implementation(Square.sqlDelightNativeDriver)
      }
    }
    ..
  }
}
l
I thought
ios
contains
iosArm64()
already. 🤔
Copy code
fun ios(
        namePrefix: String = "ios",
        configure: KotlinNativeTarget.() -> Unit = {}
    ) {
        val targets = listOf(
            iosArm64("${namePrefix}Arm64"),
            iosX64("${namePrefix}X64")
        )
        createIntermediateSourceSets(namePrefix, targets.defaultSourceSets(), mostCommonSourceSets())
        targets.forEach { it.configure() }
    }
x
hmm yeah you are right, it does seem to include both
iosArm64
and
iosX64
, must be something else causing the issue
out of curiosity - would explicitly defining each target (like above) still cause the issue?
l
Yup just tried it out. The issue still persists. I’m curious if it has to do anything with the SPM library itself. Because even a simple Kotlin object module seems to be failing 🤔
x
Are you able to extract this down to a minimal project?
l
It compiles successfully to a SPM package. But upon including it in Xcode and trying to build it it fails.
x
seems like a spm-plugin issue - better to raise a ticket in the plugin repo
do you use cocopods? any issues through the cocopods plugin?
s
Are you compiling on an Intel Mac or an M1 Mac? Can you show a Screenshot of your .xcframework folder? Can you show your build settings for “Architecture”?
The
ios-x86_64-simulator
will not work on M1 Macs. You need
ios-arm64_x86_64-simulator
to make it work in the simulator.
l
Oh is it .. any changes to the build settings I have to make then?
s
Something is wrong in your build.gradle but I can not help you with this cause I am from the iOS universe and have no Idea about the build.gradle things 🤫
l
Not an issue! Thanks a lot for identifying out the M1 mac issue 👍