概述
我在嘗試著:
- 為 Flutter 創建一個 FFI 插件
flutter_rust_bridge - 對于 iOS/macOS,使用 XCFramework(目前似乎是比通用庫更好的選擇)
簡而言之,我很難構建我的示例專案(使用我的 flutter ffi 插件)。
我做了什么
- 從生成的 rust 靜態庫(包括 macOS、iOS 和 iOS 模擬器靜態庫)創建了一個 XCFramework。光是這一點就很頭疼了。
flutter_mimir.podspec在我的ios和檔案夾中創建了以下檔案macos:
Pod::Spec.new do |spec|
spec.name = 'flutter_mimir'
spec.version = '0.0.1'
spec.license = { :file => '../LICENSE' }
spec.homepage = 'https://github.com/GregoryConrad/mimir'
spec.authors = { 'Gregory Conrad' => '[email protected]' }
spec.summary = 'Embedded instance of milli'
spec.ios.deployment_target = '9.0'
spec.osx.deployment_target = '10.11'
spec.source = { :path => '.' }
spec.preserve_paths = 'EmbeddedMilli.xcframework/**/*'
spec.vendored_frameworks = 'EmbeddedMilli.xcframework'
spec.xcconfig = { 'OTHER_LDFLAGS' => '-framework EmbeddedMilli' }
# TODO clean up following (not sure if these are actually needed here?)
# Flutter.framework does not contain a i386 slice.
spec.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
spec.static_framework = true
end
- 將我創建的移動
EmbeddedMilli.xcframework到ios和macos目錄中。 pod install運行良好。
問題
為 macOS 構建時:
Launching lib/main.dart on macOS in debug mode...
lib/main.dart:1
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-0004695C0C06801E }
{ platform:macOS, arch:x86_64, id:00006000-0004695C0C06801E }
ld: framework not found EmbeddedMilli
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如何修改我的庫的 podspec/專案構建設定以允許構建示例專案?
有關的
- 我的專案,以及我用來將 FFI 支持添加到我的庫中的 PR 。
- 如何手動將 .xcframework 添加到 Flutter iOS 插件?(對 podspec 有很大幫助,但沒有讓我的專案作業)
- 帶有 xcframework 的 Flutter 插件僅適用于不適用于 ios 模擬器的設備
uj5u.com熱心網友回復:
我的問題的答案來自這個 GitHub 執行緒。這是我的評論的副本:
以防其他人遇到這個問題,我讓 FFI 與我的跨平臺 XCFramework 一起使用ffiPlugin: true(感謝 @leisim 使用 Isar 的好例子!)。我不敢相信我沒有意識到這一點,但我的 XCFramework 正在搖搖欲墜。這是我修復它的方法(macOS 和 iOS 的代碼完全相同,但不幸的是不能符號鏈接):
my_package.podspec
Pod::Spec.new do |spec|
spec.name = 'my_package'
spec.version = '0.0.1'
spec.license = { :file => '../LICENSE' }
spec.homepage = ''
spec.authors = { 'Your Name' => '[email protected]' }
spec.summary = 'Some summary'
spec.source = { :path => '.' }
spec.source_files = 'Classes/**/*'
spec.public_header_files = 'Classes/**/*.h'
spec.vendored_frameworks = 'Frameworks/MyPackage.xcframework'
spec.ios.deployment_target = '11.0'
spec.osx.deployment_target = '10.11'
end
Classes/binding.h
void enforce_binding();
Classes/EnforceBinding.swift
public func dummyMethodToEnforceBundling() {
enforce_binding() // disable tree shaking
}
Frameworks/MyPackage.xcframework需要有一個void enforce_binding() {}功能。我用 Rust 做了這個:
/// Enforce the binding for this library (to prevent tree-shaking)
#[no_mangle]
pub extern "C" fn enforce_binding() {}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537568.html
標籤:ios扑苹果系统锈椰子类
上一篇:Docker中的C程式:fwrite(3)和write(2)無法在Windows上修改檔案,但在MacOS上不能
