我正在使用 Flutter(适用于 Android)开发一个应用程序,其核心基于仅使用 C++ 和 python 开发的库。因此,我想知道如何在我的 dart 代码(C++ 版本或 Python 版本)中使用这个库。
最佳答案
补充信息 (2021-05-05)
来自@FacundoFarall 对原始问题的评论:
Try this video by Richard Heap, it helped me quiet a lot. He explains with an example how to interact between the Dart code of your Flutter app, and the C++ library you're using, all through dart:ffi. I'd also recommend checking out this post for a way to debug the C++ code while running it through a Flutter app.
更新 (2019-09-10)
今天是 released Dart 2.5 (和 flutter 1.9)。 Dart 2.5 的新增功能之一是“用于直接从 Dart 调用 C 代码的 dart:ffi 外部函数接口(interface)”。我还没有检查它,但它应该提供与 C(和 C++)代码接口(interface)的更直接的路径。
另见announcement video (确认旧方法和新方法)。
旧答案(仍然有效)
我会看看 Platform Channels,这是一种将 Flutter 代码与平台原生代码通信的方式(例如,Android 上的 Java/Kotlin,iOS 上的 Objective C/Swift)。从那里,您可以使用常规 NDK 机制使用您的 C++ 库。
你可以看到Flutter Platform Channels的介绍和 Getting Started with the NDK .
也许有更直接的路线,但这是我知道可行的路线。
关于android - 如何在 flutter (android)应用程序中使用 C++ 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54952245/