question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build swift package for simulator and device does not work anymore

See original GitHub issue

Hi guys, I really love this framework - it is awesome.

The only issue I run into now is, when using the newest android studio canary build 15 of android studio with the new build and compile configurations and options and preliminary support for Apple Silicon, only an ios-x86_64-simulator framework is generated. The ios-arm64 framework is missing. The release notes for the new android studio: https://androidstudio.googleblog.com/2021/04/android-studio-arctic-fox-canary-15.html

The packForXCode looks like this:

val packForXcode by tasks.creating(Sync::class) {
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
    val targetDir = File(buildDir, "xcode-frameworks")

    group = "build"
    dependsOn(framework.linkTask)
    inputs.property("mode", mode)

    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

The further configuration in the kotlin {} block for iOS looks like this atm:

kotlin {
    android() {
        publishAllLibraryVariants()
    }

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            :: iosArm64
        else
            :: iosX64

    iosTarget("ios") {
        binaries {
            framework {
                baseName = "my-shared"
            }
        }
    }

    val ktorVersion = "1.4.0"
    .
    .
    .
}

And my configuration for this framework looks like this:

multiplatformSwiftPackage {
    val spmPath = "<my-spm-path>"

    swiftToolsVersion("5.3")

    spmPath?.apply {
        outputDirectory(File(spmPath))
        targetPlatforms {
            iOS { v("14") }
        }
    }
}

Can you please help me with that? What can I change to make that work? I use the version 2.0.3 of your plugin.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

2reactions
ruisilvestre-snappcommented, Jul 8, 2021

The solution by @ashley-figueira works fine. Basically replace the default iosTarget with ios (since iosTarget seems to be a workaround deprecated by the “hierarchical project structure” according to https://kotlinlang.org/docs/migrating-multiplatform-project-to-14.html#try-the-hierarchical-project-structure).

I could then use the ‘shared kotlin’ package as a framework dependency on my ios swift package.

Additionally, this change does not seem to break the default ios project integration (I can still build an app that uses the shared module directly and run for device/simulator).

2reactions
ashley-figueiracommented, Jun 26, 2021

@rb090 If you are using this gradle plugin there is no reason you need the packForXcode is there? Have you added the two lines I mentioned to your gradle.properties file?

kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false

This is my complete builde.gradle.kts

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3"
}

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }

    sourceSets {
        val commonMain by getting 
        val commonTest by getting
        val androidMain by getting
        val androidTest by getting
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(30)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(30)
    }
}

multiplatformSwiftPackage {
    packageName("Shared")
    swiftToolsVersion("5.3")
    targetPlatforms {
        iOS { v("13") }
    }
    outputDirectory(File(rootDir, "swift-package"))
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] iOS simulators not showing up - Apple Developer
This problem first appeared when I updated Xcode 6.1 to version 6.2. ... When opening the device build, there are no simulators listed...
Read more >
Can't build on simulator for architecture arm64 · Issue #291
Swift Package Manager lacks proper version locking at present, so is not a suitable replacement for Cocoapods, for any app that must be...
Read more >
Xcode project not showing list of simulators - Stack Overflow
In my case I tried to run a project which was built using iOS8.4 but I have ... So, the simulators are not...
Read more >
Oh dear! Build errors? - LoopDocs - GitHub Pages
Open your project in Xcode as normal. Then go to the menu bar at the top of the screen and find the "Product"...
Read more >
Compiling for iOS on Apple M1 - Mercari Engineering Blog
This new computer is not an Intel based computer anymore but an ... M1 compilation for recent ios simulators; Swift compiler overview ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found