hi, I'm trying to migrate to `embedAndSignAppleFra...
# multiplatform
t
hi, I'm trying to migrate to
embedAndSignAppleFrameworkForXcode
and followed the steps here but am getting:
Copy code
Task 'embedAndSignAppleFrameworkForXcode' not found in project ':SharedCode'
n
This task relies on a bunch of environment variables defined by XCode. You won’t see it in the terminal but hopefully it should work when called from XCode
t
that's the error I'm getting from within Xcode when I build
and I'm configured with Kotlin 1.6.10
is there anything else I can do to diagnose what the issue is?
r
Some possible causes of this error: • The
baseName
isn't set for the framework (had that issue recenlty) • If you for example try to build an iOS app for an M1 simulator and your shared module doesn't have the
iosSimulatorArm64
target
t
@Rick Clephas thanks! I've set the
baseName
and have a
iosSimulatorArm64
target (this is on an M1) and I think I've gotten past this issue. My current issue now seems to be linking:
Copy code
dyld[28834]: Library not loaded: @rpath/SharedCode.framework/SharedCode
  Referenced from: /Users/treitter/Library/Developer/CoreSimulator/Devices/A5638492-9E3A-4766-B4D4-6827DF4DBAC8/data/Containers/Bundle/Application/CADE4DEF-489A-4E7F-B600-8CFAA803F19D/DoubleStrain <http://dev.app/DoubleStrain|dev.app/DoubleStrain> dev
  Reason: tried: '/Users/treitter/Library/Developer/Xcode/DerivedData/DoubleStrain-csfvqjqyopvjufbkvgenmyhjexpz/Build/Products/Debug-iphonesimulator/SharedCode.framework/SharedCode' (no such file), '/Users/treitter/Library/Developer/Xcode/DerivedData/DoubleStrain-csfvqjqyopvjufbkvgenmyhjexpz/Build/Products/Debug-iphonesimulator/PackageFrameworks/SharedCode.framework/SharedCode' (no such file),
...
and it crashes. That seems like it would be an issue of the framework search paths not being set but I do have this:
Copy code
$(SRCROOT)/../SharedCode/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
though that doesn't seem to appear in the list of paths that show up above (even including the ones I left out)
r
Hmm alright haven't seen that one before. Did you also set the "other linker flags" mentioned in the blog post?
t
@Rick Clephas yeah, they're set to
$(inherited) -framework SharedCode
. Xcode renders each of those 3 elements on separate lines but I hope that doesn't matter. I don't think it has in the past
hmm, it seems my KMM framework flat-out isn't being built. I had a couple older builds in place and I guess they were in a partially-working state which is why I could build and run the app but it would crash
r
Strange is Xcode not executing the gradle task or does the gradle task fail to built the framework?
t
OK, I think have something working now. I had to cut out the
ios
targets in my Gradle down to just:
Copy code
iosSimulatorArm64("ios") {
        binaries {
            framework {
                baseName = "SharedCode"
            }
        }
    }
which works for now since I'm only building on an M1 Mac and running in the simulator.
but how do I integrate the targets needed to run on an iPhone, etc? For some reason, I can't quite work that out
r
Something like the following should work:
Copy code
val iosArm64 = iosArm64()
val iosX64 = iosX64()
val iosSimulatorArm64 = iosSimulatorArm64()

sourceSets {
    val iosMain by creating
    val iosTest by creating
    listOf(iosArm64, iosX64, iosSimulatorArm64).forEach {
        it.binaries {
            framework {
                baseName = "SharedCode"
            }
        }
        getByName("${it.targetName}Main") {
            dependsOn(iosMain)
        }
        getByName("${it.targetName}Test") {
            dependsOn(iosTest)
        }
    }
}
Depending on the Xcode environment variables Kotlin will figure out which targets to build.
t
@Rick Clephas great, that seems to work. Thanks for all your help!
👍🏻 1