Skip to content

Kaluga 0.3.0 Migration (Apple Silicon Targets)

Carmelo Gallo edited this page May 4, 2022 · 9 revisions

Intro

Since version 0.3.0 we have introduced the new Apple Silicon targets ( only iOS for now, macOS will follow soon ) support which means that the way we were declaring iOS targets in build.gradle has changed along with Xcode framework setup. Following you'll find a guideline to how make your project compatible with this new version of Kaluga and this new settings is the new base from now on on all our projects.

All project dependencies or submodules MUST support Apple Silicon or have the same changes described in this guideline in order to have the whole project build properly.

Guideline

1. build.gradle.kts

In this file we need to add the iosSimulatorArm64 target.

Code to be removed

...
var sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val isArm64 = sdkName.startsWith("iphoneos") // <-- from KMM generated project, but a bit suspect
val iosArchitecture = if (isArm64) { "Arm64" } else { "X64" }
...
extra["sdkName"] = sdkName
extra["isArm64"] = isArm64
extra["iosArchitecture"] = iosArchitecture
...

Or any other static reference to iOS targets

Code to be replaced - Part 1

val target: KotlinNativeTarget.() -> Unit = ...

ios(configure = target) 

or 

ios()

with

iosX64(configure = target)
iosArm64(configure = target)
iosSimulatorArm64(configure = target)

or

iosX64()
iosArm64()
iosSimulatorArm64()

Code to be replaced - Part 2

There is no need anymore to reference the dir since the new way with dependOn does it.

named("ios${iosArchitecture}Main") {
    kotlin.srcDirs("src/iosMain/kotlin")
}
named("ios${iosArchitecture}Test") {
    kotlin.srcDirs("src/iosTest/kotlin")
}

or

val iosMain by getting
val iosTest by getting

with

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)
}

val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
    dependsOn(commonTest)
    iosX64Test.dependsOn(this)
    iosArm64Test.dependsOn(this)
    iosSimulatorArm64Test.dependsOn(this)
}

2. Xcode setup

Code to be removed

Remove all the reference about the shared framework in all Xcode targets from this panel:

Screenshot 2022-03-09 at 10 11 18

Code to be replaced - Part 1

Either in Build Phases or in xcconfig files if you are using those, replace the gradlew script with the follow one

# Root where to run gradlew
cd "$SRCROOT/../"
# Select which module needs to run the task
./gradlew :YOUR_MODULE_NAME:embedAndSignAppleFrameworkForXcode

packforxcode-in-project-settings

If in your old script there were some User-Defined properties, just remove them as well in your Build Settings. Just scroll to the very bottom of Build Settings and check them under User-Defined.

Code to be replaced - Part 2

Either in Build Settings or in xcconfig files if you are using those, replace the FRAMEWORK_SEARCH_PATHS with

# Select from which module needs to get the framework
$(SRCROOT)/../YOUR_MODULE_NAME/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)

framework-search-path-in-xcode-project-settings

Code to be replaced - Part 3

In Other Linker flags under the Linking section:

$(inherited) -framework shared

other-linker-flags-in-xcode-project-settings

3. Error KOTLIN_FRAMEWORK_BUILD_TYPE

In case you get KOTLIN_FRAMEWORK_BUILD_TYPE error while building, just add that in your User-Defined inside Build Settings as below: Screenshot 2022-05-04 at 12 49 01