https://kotlinlang.org logo
a

Arkadii Ivanov

11/06/2020, 2:24 PM
I'm using the "packForXcode" Gradle task to build my shared library as a Framework. This works fine from Xcode when the Framework is not built yet or I don't change the build target in Xcode. But once I already have the Framework build for e.g. "iOS" and I switch to "iOS Simulator", build fails. It fails before even executing the script from Build Phases (it is put on the second position from top). Is there any solution for this? Currently I can only manually delete the Framework folder before building.
youtrack 2
4
d

dazza5000

11/06/2020, 2:34 PM
I think we need to understand / have a solution to generate xcframeworks
a

Arkadii Ivanov

11/06/2020, 2:35 PM
Fat frameworks are possible but they are slow, since every time it builds all targets.
d

dazza5000

11/06/2020, 2:35 PM
do you have any reference on how to build them in an MP project? That would solve this issue.
t

Thomas

11/06/2020, 2:37 PM
I have this as well. A gradle clean works, too. I also noticed that Xcode always uses the previously built framework, so I need to tap run again. So if you change some Kotlin code, and run in Xcode, it uses the previously built Kotlin code. Clicking run again in Xcode uses the new code. Not sure what is wrong with my project configuration.
a

Arkadii Ivanov

11/06/2020, 2:39 PM
@dazza5000 We have fat framework setup for our sample project for Reaktive (e.g. there is a special task to build the Fat framework)
But currently I'm adding another Xcode project and would like to avoid fat frameworks, since they are slow in build.
@Thomas I think my problem is a bit different. I'm not changing the Kotlin code, just switching to another build target (iOS -> iOS Simulator). And the build script is not event executed before build fails.
t

Thomas

11/06/2020, 2:46 PM
@Arkadii Ivanov that is exactly the issue I am having too. I get the same error when switching between targets (device and simulator). It seems that Xcode checks and uses the framework that was built previously. That is why it shows an error when switching targets. And in my case it also uses the previously built framework when building again for the same target when changing Kotlin code.
a

Arkadii Ivanov

11/06/2020, 2:46 PM
Will use Fat framework approach as a fallback if there is no solution.
d

dazza5000

11/06/2020, 3:55 PM
awesome - i will need to do this on my projects now that xcode 12 is out - thank you for sharing
a

Arkadii Ivanov

11/06/2020, 3:58 PM
Yeah, seems working
n

ntherning

11/19/2020, 9:04 AM
This is how we do it. Only builds the needed slice (arm64, x86_64, debug, release). It also produces an Xcode dependency file to let Xocde detect dirty files on the kotlin side and only invoke Gradle when needed. It's a bit complicated to set up but works flawlessly so far for us. https://gist.github.com/ntherning/dafd5979bdfb660bbf516066ca056931
a

Arkadii Ivanov

11/19/2020, 9:06 AM
@ntherning looks like this is a great solution, will give it a try. Thanks for sharing! PS: sounds like a good topic for an article/blog post.