android - 如何在 Flutter 包中使用原生 C 库
问题描述
我有一个用 C 编写的库,我以前通过 JNI 从 java android 应用程序中使用过它。
我现在转而使用颤振,计划是制作一个包装 C 库的颤振包。
包的flutter项目已经创建,计划使用平台通道(invokeMethod来调用一些简单的Java方法来调用库的JNI。我想我已经实现了大部分。
但是问题是,我通常会将有关库和 JNI 存在的信息添加到我的 android java 项目的 build.gradle 中。但是,当我在颤振包的结构中工作时,我找不到这些文件。如果我改为构建一个标准的颤振项目(一个带有 UI 的应用程序),我突然有了 build.gradle 文件。
如何添加这些 gradle 文件,或者我应该将有关 lib/JNI 的信息添加到其他一些特定于颤振的文件中?多层 dart->platformChannel -> java -> jni -> C library 方法听起来是正确的做法吗?或者,还有更好的方法?
解决方案
Are you sure you created a Flutter plugin project (not a package)? A plugin is a type of package with Dart/Kotlin (or Java)/Swift (or Obj-C) code implementing the Flutter-native layer, plus an example app that exercises and demonstrates use of the plugin.
A Flutter plugin has 3 build.gradle files:
./android/build.grade
where you set the plugin's min SDK, dependencies, etc./example/android/build.grade
which is generally left unchanged./example/android/app/build.gradle
which is where you set things for the example app
Any changes you make to (1) bubble up to the example app (which is just a sample app that uses your plugin). Likewise, when you use the plugin in a different app, that app just picks up (1) from your plugin.
Add your dependencies to (1).
推荐阅读
- java - FXMLLoader.load() 在 pre-java 9 样式中工作正常,但在模块中失败
- html - 当导航栏在移动设备上折叠时,背景正文向上滚动
- typescript - 有没有办法获取打字稿对象的所有必需属性
- sql - SQL 在 WHERE 语句中使用参数
- c# - 为什么我调用 ASPNET Core 2.1 Database Migrate 的实现没有实际应用迁移?
- java - 使用 Java 流按集合属性分组
- c# - 在 TCP 中按下 Enter 键之前如何接收数据流?
- python - 如何从python中的文件中以特定顺序获取输入
- karate - 可以将每个场景的相同断言放在单独的文件中以避免空手道重复?
- testing - 如何测试使用 React 测试库安装后立即卸载的组件?