Im following this <guide> to migrate my android ap...
# multiplatform
a
Im following this guide to migrate my android app to KMM, but when i attempt to build the xcode project it gives this error:
Copy code
ld: warning: directory not found for option '-F/Users/xxx/My Apps/my_project/shared/build/xcode-frameworks/Debug/macosx13.3'
ld: framework not found shared
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Which makes sense as the folder xcode-frameworks doesnt exist. Is this supposed to be generated for me when i make & build the shared module in android? Because i’ve done this already
m
What gradle command had you execute ?
a
All ive done so far is re-build my android studio project after adding a shared module
m
strange, because i try to execute for iOS if i look your error
a
So im also attempting to build the xcode project too as instructed by the guide, and that error is in the xcode window
m
can you post your iOS part in your gradle please
a
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
    targetHierarchy.default()

    android {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                //put your multiplatform dependencies here
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}

android {
    namespace = "com.xxx.xxx.shared"
    compileSdk = 33
    defaultConfig {
        minSdk = 21
    }
}
this was all auto-generated by android studio when creating the module
m
ok and how do you integrate it in your iOS project?
a
thats the part im stuck on now i believe, the guide says
On the Build Settings tab, switch to All build settings and specify the Framework Search Path under Search Paths:
Copy code
$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
but as mentioned
xcode-frameworks
folder doesnt exist
m
ok, so this how i use KMP with iOS: in the gradle, replace listOf for iOS :
Copy code
val xcf = XCFramework()
listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach {
    it.binaries.framework {
        baseName = "MyCardKmm"
        xcf.add(this)
    }
}
and after that execute: ./gradlew assembleDebugXCFramework And you will have your folder 🙂
a
unfortunately this returns this error
* What went wrong:
Task 'assembleDebugXCFramework' is ambiguous in root project 'xxx' and its subprojects. Candidates are: 'assembleDebugIosFatFrameworkForSharedXCFramework', 'assembleDebugIosSimulatorFatFrameworkForSharedXCFramework', 'assembleDebugMacosFatFrameworkForSharedXCFramework', 'assembleDebugTvosFatFrameworkForSharedXCFramework', 'assembleDebugTvosSimulatorFatFrameworkForSharedXCFramework', 'assembleDebugWatchosFatFrameworkForSharedXCFramework', 'assembleDebugWatchosSimulatorFatFrameworkForSharedXCFramework', 'assembleSharedDebugXCFramework'.
i ran the
assembleSharedDebugXCFramework
which gave me XCFrameworks folder in shared/build which is great, but it does differ to the naming thats given in the official guide which would be
shared/build/xcode-frameworks
? But unfortunately still when trying to build the xcode project it says
ld: warning: directory not found for option '-F/Users/xxx/My Apps/xxx/shared/build/XCFrameworks/Debug/macosx13.3'
Again the template for this in xcode is $(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME) What would be my sdk name?
okay ive got it working - i manually corrected some of the path variables rather than letting xcode generate it for me /Users/xxx/My Apps/xxx/shared/build/XCFrameworks/Debug/shared.xcframework/ios-arm64_x86_64-simulator thanks for your help @Maxime Vince 👍
m
Your welcome and now enjoy 🙂
c
thanks. id didn't know about this guide. I gathered some video resources here https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1691283600537169
🙌 1
188 Views