在Kotlin Multiplatform Mobile(KMM)项目中使用OpenCV
设置:
我们当前正在使用iOS和Android上的OPENCV进行图像处理。在Android上,我们将OPENCV导入为.aar
,在iOS上,我们通过可可录将其导入,他们称其为相同的基础功能。
问题:
我们想进行一个KMM项目,可以在其中导入OpenCV并共享业务逻辑。我们正在使用期望/实际
在平台特定代码中依赖OpenCV。 我们可以通过在Androidmain
中导入相同的来使其适用于Android。 我们的问题是iOS。当前,KMM不支持与C ++的互操作性(写入OpenCV) - 请参见 https:/noreferrer“> https:/ /kotlinlang.org/docs/roadmap.html#remaved-items
我们尝试的是:
我们尝试通过gradle链接.framework
。文件指向OpenCV中的.hpp
文件,但是在尝试同步Gradle时,我们会收到一个错误xxx.hpp标头。
build.gradle.kts
iosX64() {
compilations.getByName("main") {
val OpenCV by cinterops.creating {
// Path to .def file
defFile("src/iosMain/cinterop/OpenCV.def")
// Directories for header search (an analogue of the -I<path> compiler option)
includeDirs("../iosApp/Pods/OpenCV/opencv2.framework/Headers/Core")
}
}
binaries.all {
// Linker options required to link to the library.
linkerOpts("-L/../iosApp/Pods/OpenCV/opencv2.framework", "-lopencv2")
}
}
opencv.def
headers = cvstd.hpp
package = OpenCV
问题:
是否有任何方法可以依赖kmm中的opencv?
Setup:
We are currently using OpenCV on iOS and Android for image processing. On Android we import OpenCV as a .aar
and on iOS we import it via Cocoapods, and they call the same underlying functions.
Problem:
We would like to have a KMM project where we can import OpenCV and share the business logic. We are using expect/actual
to depend on OpenCV in platform specific code.
We can make it work for Android by importing the same .aar
in androidMain
.
Our problem is with iOS. Currently KMM doesn't support interoperability with C++ (which OpenCV is written in) - see https://kotlinlang.org/docs/roadmap.html#removed-items
What we have tried:
We tried to link a .framework
via Gradle and create .def
files to point to the .hpp
files in OpenCV but we get an error xxx.hpp header must be compiled as C++
when trying to sync Gradle.
build.gradle.kts
iosX64() {
compilations.getByName("main") {
val OpenCV by cinterops.creating {
// Path to .def file
defFile("src/iosMain/cinterop/OpenCV.def")
// Directories for header search (an analogue of the -I<path> compiler option)
includeDirs("../iosApp/Pods/OpenCV/opencv2.framework/Headers/Core")
}
}
binaries.all {
// Linker options required to link to the library.
linkerOpts("-L/../iosApp/Pods/OpenCV/opencv2.framework", "-lopencv2")
}
}
OpenCV.def
headers = cvstd.hpp
package = OpenCV
Question:
Is there any way to depend on OpenCV in KMM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论