调试“找不到共享代码”问题
解决首次运行时最常见的链接问题
调试“找不到共享代码”问题 是 CoddyKit 上的免费 Kotlin Multiplatform Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Kotlin Multiplatform Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Kotlin Multiplatform Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
The Classic First-Run Wall
Almost everyone hits it once: iOS builds but Swift cannot find your shared API. Let's debug shared code not found calmly. 🛠️
Confirm the Framework Built
First, run the Gradle framework task directly. If it fails outside Xcode, the framework never existed and Swift had nothing to link.
./gradlew :shared:embedAndSignAppleFrameworkForXcodeCheck the import Name
Swift must import the exact baseName set in build.gradle.kts. A mismatched name is the most common no-such-module error.
import sharedVerify the Build Phase Order
The Gradle build phase must run before Compile Sources. If it sits too low in the list, Swift compiles before the framework exists.
Framework Search Paths
Xcode needs to know where the framework lives. Check that Framework Search Paths points at the Gradle output folder for your target.
Open the Right File
Using CocoaPods but opened the .xcodeproj? Pods are missing. Close it and open the .xcworkspace instead.
Wrong Architecture Linked
An arm64 framework will not link into an x86 simulator. Make sure the framework was built for the same architecture as your run target.
Read the Build Log Top-Down
Expand the failing step in the build log and find the first error. A later linker complaint is often just a symptom of an earlier failure.
Clean Out Stale Output
Old artifacts can confuse the linker. A clean Gradle build plus an Xcode clean often clears a stubborn not-found error.
./gradlew cleanPublic API Visibility
Only public Kotlin declarations cross to Swift. If a class is internal, Swift will not see it no matter how the framework links.
Most Fixes Are Wiring, Not Logic
These errors look scary but are almost always config: name, path, order, or architecture. Check those four and you'll be unblocked. ✨
Quick Check
Let's confirm a frequent cause of this error.
Recap
You learned to debug not-found errors by checking the framework built, the import name, build-phase order, search paths, and architecture. Most fixes are config, not code. 🎉
常见问题解答
「调试“找不到共享代码”问题」课时是免费的吗?
是的 — 「调试“找不到共享代码”问题」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Kotlin Multiplatform Academy 课程的其余内容,请升级到 CoddyKit PRO。 Kotlin Multiplatform Academy 课程共包含 4 节课。
「调试“找不到共享代码”问题」这节课中我会学到什么?
解决首次运行时最常见的链接问题 你通过在浏览器中直接运行的动手代码来练习 Kotlin Multiplatform Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Kotlin Multiplatform Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Kotlin Multiplatform Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「调试“找不到共享代码”问题」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Kotlin Multiplatform Academy 课中编写并运行代码吗?
能。每节 Kotlin Multiplatform Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。