[英]How Do Transitive Dependencies in KMM and iOS work?
Lets say I have a package, Shared Package that is shared with two KMM projects: KMM Project A and KMM Project B.假设我有一个 package,共享 Package 与两个 KMM 项目共享:KMM 项目 A 和 KMM 项目 B。
So we have Shared Package -> KMM Project A and Shared Package -> KMM Project B.所以我们有共享 Package -> KMM 项目 A 和共享 Package -> KMM 项目 B。
Now I want to use both KMM Project A and KMM Project B in my iOS app.现在我想在我的 iOS 应用程序中同时使用 KMM 项目 A 和 KMM 项目 B。 How does that work?
这是如何运作的? Is Shared Package bundled with both frameworks (ie I am including the same dependency twice?).
Shared Package 是否与这两个框架捆绑在一起(即我两次包含相同的依赖项?)。 Furthermore, does the Shared Package need to be a KMM Project to allow KMM Project A and B to generate the relevant iOS frameworks?
此外,共享 Package 是否需要成为 KMM 项目才能允许 KMM 项目 A 和 B 生成相关的 iOS 框架? Or can it be a pure Kotlin project?
或者它可以是一个纯粹的 Kotlin 项目?
Here is a diagram that might give more explanation of the situation I am trying to understand.这是一张图表,可能会对我试图理解的情况提供更多解释。
You need a wrapper "unbrella" module that depends on KMM Project A and KMM Project B, and have that generate your Xcode Framework.您需要一个依赖于 KMM 项目 A 和 KMM 项目 B 的包装“unbrella”模块,并让它生成您的 Xcode 框架。
You can technically generate 2 frameworks, one for each of the KMM Project A and B, but they will both have a copy of "Shared Package", along with relevant portions of the Kotlin standard lib, and most importantly, those 2 frameworks will be distinct on a binary level, so they can't communicate.从技术上讲,您可以生成 2 个框架,一个用于 KMM 项目 A 和 B,但它们都将具有“共享包”的副本,以及 Kotlin 标准库的相关部分,最重要的是,这两个框架将是在二进制级别上不同,因此它们无法通信。
By that I mean, if "Shared Package" has a data class Foo
, and you get that as a result from a call to "KMM Project A", say fun makeAFoo():Foo
, and you have a function in "KMM Project B" that's defined as fun takeAFoo(foo:Foo)
, the Foo
instance you get from makeAFoo()
cannot be passed into takeAFoo(foo:Foo)
.我的意思是,如果“共享包”有一个
data class Foo
,并且你通过调用“KMM Project A”得到它,比如说fun makeAFoo():Foo
,你在“KMM Project”中有一个 function B" 被定义为fun takeAFoo(foo:Foo)
,您从makeAFoo()
获得的Foo
实例不能传递给takeAFoo(foo:Foo)
。
So, the short answer is you need a wrapper module that pulls in both of the "Shared Package" modules.所以,简短的回答是你需要一个包装器模块来拉入两个“共享包”模块。 You'll also need to export them through the umbrella.
您还需要通过保护伞导出它们。
See: https://touchlab.co/multiple-kotlin-frameworks-in-application/ and https://kotlinlang.org/docs/mpp-build-native-binaries.html#export-dependencies-to-binaries请参阅: https://touchlab.co/multiple-kotlin-frameworks-in-application/和https://kotlinlang.org/docs/mpp-build-native-binaries.html#export-dependencies-to-binaries
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.