Thread
#multiplatform
    Umar Ata

    Umar Ata

    1 year ago
    Hi there, My name is Umar, I am from India Nice meeting you to all worlds best developers I have a question I actually transformed one of my android application logic code to kotlin multiplatform Problem: When the iOS developer needs the logic code I need to execute the command
    *cd* "$SRCROOT/.."
    ./gradlew :shared:packForSimulator -PXCODE_CONFIGURATION=${CONFIGURATION}
    shared is the name of my multiplatform module I am sharing the common code between Android and iOS so the problem is that whenever I run above command from runScript of XCode it actually builds the framework for Selected device like either iPhone device or iPhone Simulator and it never gives me one framework that runs on both iOS device and simulator
    Umar Ata

    Umar Ata

    1 year ago
    Thank you, I want to know that if I use Fat framework so can I use same in Android?
    Kris Wong

    Kris Wong

    1 year ago
    i don't understand the question. Android doesn't use frameworks.
    Umar Ata

    Umar Ata

    1 year ago
    I have one android app, I want the same logic in both iOS and Android, so I copied my logic code in newly created shared multiplatform module and in Android I am using it as a project dependency like
    implementation project(':shared')
    and for iOS I use script to generate xcode-frameworks
    and then use it in there
    I don’t want to code separate framework for iOS, I only want to make framework that runs for both iOS device and simulator
    for now I created two functions in gradle each for iOS device and simulator
    val packForXCode by tasks.creating(Sync::class) {
        group = "build"
        val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
        //val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
        val targetName = "iosArm64"//+  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)
    }
    val packForSimulator 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)
    }
    so when I want to generate framework for iPhone device I use ./gradlew shared😛ackFor XCode and for simulator I use ./gradlew shared😛ackForSimulator
    in this way I don’t need to select iPhone or Simulator in XCode
    g

    georg

    1 year ago
    You could also create an XCFramework. It contains both the framework for the device and the simulator. I created a Gradle plugin that can do that for you. Check it out on Github: https://github.com/ge-org/multiplatform-swiftpackage
    Kris Wong

    Kris Wong

    1 year ago
    a normal framework file contains the same. there's no need for a plugin
    g

    georg

    1 year ago
    With a fat framework you need to remove the unused architectures (i.e. simulator) before uploading to the App Store. Otherwise Apple will reject the binary. An xcframework does not require this step
    Kris Wong

    Kris Wong

    1 year ago
    gotcha
    or just use the coacoapods plugin and don't worry about it
    g

    georg

    1 year ago
    True. It takes care of removing the simulator frameworks. But then you’re stuck with Cocoapods 😉 There are plenty of options out there. Just pick whatever suits your needs
    Umar Ata

    Umar Ata

    1 year ago
    So if I setup cocoa pods for my framework then I don’t need to generate framework?
    but then it will become publicly available ?
    g

    georg

    1 year ago
    It wont’t be public unless you publish it. There’s a nice article by Jetbrains about the integration of Cocoapods and KMP. https://kotlinlang.org/docs/reference/native/cocoapods.html
    Umar Ata

    Umar Ata

    1 year ago
    okay