-
Notifications
You must be signed in to change notification settings - Fork 564
SwiftUI preview is not working when using the CocoaPods plugin #3059
Comments
Thanks, confirmed. |
After some investigation I consider this a bug in SwiftUI preview implementation. This implementation internally produces Xcode seems to apply some workaround for this by avoiding linking static dependencies. This workaround works in simple cases but doesn't work for CocoaPods dependencies. You can verify this by creating SwiftUI project with e.g. Kotlin/Native produces static frameworks when imported via CocoaPods, so it is technically contained twice which results in the crash you reported. |
Still experiencing this with Xcode 11.3 beta (11C24b). I thought the issue might be addressed by a fix introduced in 11.2 but it didn't seem to help.
|
Problem still persists in Xcode 11.3 (11C29) |
Do any workarounds exist? Solutions posted on Cocoapods issues tracker doesn't work in kotlin-native dependency case. |
Please try to make Kotlin framework dynamic. E.g. with Gradle Kotlin DSL: kotlin {
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework> {
isStatic = false
}
}
} If you use a |
Notice: I am new to iOS development so I might misunderstand some basic concepts in iOS build toolchain or miss some obvious steps 😅 When I set framework to be compiled as dynamic I get this during build: Gradle task error during xcode build
My gradle project structure:
When using |
I can confirm this works. I had some trouble initially but after ensuring the framework search paths for both my project and the pods project were set to $(inherited) and recursive, it started working. Thanks! Edit: I created a swift_ui branch for my template project, if anyone wants a working example |
@audkar CocoaPods plugin is not supposed to work flawlessly with dynamic Kotlin frameworks, so you need to add explicit linker options to link Kotlin framework with dependencies from CocoaPods. |
In case you are using the new template from Android Studio's KMP you will have |
See KT-35723 for built-in support for dynamic frameworks in Kotlin CocoaPods Gradle plugin. |
I cannot get Kotlin native working with the new SwiftUI preview. SwiftUI works fine in the simulator, but the Xcode preview shows this error:
I could only reproduce this with the CocoaPods plugin, so that seems related.
Here is a sample project. I added my changes as separate commits so you can see what I did.
Open the Xcode project in Xcode 11 on Mac OS Catalina beta. (you might need to follow this readme file to set it up). Navigate to the SwiftUIView.swift file and you will get this error in the preview:
Here is the crash log the screenshot is referring to.
I originally reported this issue on Slack.
The text was updated successfully, but these errors were encountered: