如何解决如何在 Flutter 中使用 dart:ffi?
我一直在思考如何在 Flutter 中实现 dart::ffi,特别是 hello_world example。
从基本的 flutter create
项目(以及一个已经编译的 hello_world.dll
)开始尝试:
void main() {
final dylib = ffi.DynamicLibrary.open('hello_world.dll');
final HelloWorld hello = dylib
.lookup<ffi.NativeFunction<hello_world_func>>('hello_world')
.asFunction();
hello();
runApp(MyApp());
}
导致:
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
package:testing_flutter/main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:61913/wRTGFN76kik=/ws
E/flutter (11980): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library (dlopen failed: library "hello_world.dll" not found)
E/flutter (11980): #0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
E/flutter (11980): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
E/flutter (11980): #2 main
package:testing_flutter/main.dart:8
E/flutter (11980): #3 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:140:25)
E/flutter (11980): #4 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (11980): #5 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (11980): #6 _runZoned (dart:async/zone.dart:1788:10)
E/flutter (11980): #7 runZonedGuarded (dart:async/zone.dart:1776:12)
E/flutter (11980): #8 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:133:5)
E/flutter (11980): #9 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (11980): #10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (11980):
我是否还需要一个 .dylib
版本,例如 in the example?
var libraryPath =
path.join(Directory.current.path,'hello_library','libhello.so');
if (Platform.isMacOS)
libraryPath =
path.join(Directory.current.path,'libhello.dylib');
if (Platform.isWindows)
libraryPath = path.join(
Directory.current.path,'Debug','hello.dll');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。