使用 pod 依赖项创建 Flutter 插件
Posted
技术标签:
【中文标题】使用 pod 依赖项创建 Flutter 插件【英文标题】:Create Flutter Plugin with pod dependencies 【发布时间】:2019-07-26 21:05:59 【问题描述】:我创建了一个带有“FacebookShare”依赖项的颤振插件。 我的 pod 规格如下所示,
Pod::Spec.new do |s|
s.name = 'plugin name'
s.version = '0.0.2'
s.summary = 'A new Flutter plugin for share image and text in social media'
s.description = <<-DESC A new Flutter plugin for share image and text in social media
DESC
s.homepage = 'https://github.com/jayarajm/flutter_share_social_media.git'
s.license = :file => '../LICENSE'
s.author = '...' => '...'
s.source = :path => '.'
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'FacebookShare'
s.ios.deployment_target = '8.0'
s.static_framework = true
end
在示例项目中,插件引用本地路径。所以我没有收到安装 pod 或运行项目的任何问题。 发布到“https://pub.dartlang.org/”后。
我尝试在项目中使用 dart 包,但在安装 pod 时遇到问题。我附上了下面的错误,
CocoaPods' output:
↳
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
Fetching external sources
-> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
-> Fetching podspec for `flutter_share_social_media` from `.symlinks/plugins/flutter_share_social_media/ios`
Resolving dependencies of `Podfile`
Comparing resolved specification to the sandbox manifest
A Bolts
A FBSDKCoreKit
A FBSDKShareKit
A FacebookCore
A FacebookShare
A Flutter
A flutter_share_social_media
Downloading dependencies
-> Installing Bolts (1.9.0)
> Copying Bolts from `/Users/jayaraj_m/Library/Caches/CocoaPods/Pods/Release/Bolts/1.9.0-ac656` to `Pods/Bolts`
-> Installing FBSDKCoreKit (4.40.0)
> Copying FBSDKCoreKit from `/Users/jayaraj_m/Library/Caches/CocoaPods/Pods/Release/FBSDKCoreKit/4.40.0-ae214` to `Pods/FBSDKCoreKit`
-> Installing FBSDKShareKit (4.40.0)
> Copying FBSDKShareKit from `/Users/jayaraj_m/Library/Caches/CocoaPods/Pods/Release/FBSDKShareKit/4.40.0-0e459` to `Pods/FBSDKShareKit`
-> Installing FacebookCore (0.5.0)
> Copying FacebookCore from `/Users/jayaraj_m/Library/Caches/CocoaPods/Pods/Release/FacebookCore/0.5.0-74288` to `Pods/FacebookCore`
-> Installing FacebookShare (0.5.0)
> Copying FacebookShare from `/Users/jayaraj_m/Library/Caches/CocoaPods/Pods/Release/FacebookShare/0.5.0-963b4` to `Pods/FacebookShare`
-> Installing Flutter (1.0.0)
-> Installing flutter_share_social_media (0.0.2)
- Running pre install hooks
[!] The following Swift pods cannot yet be integrated as static libraries:
The Swift pod `FacebookCore` depends upon `Bolts` and `FBSDKCoreKit`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
The Swift pod `FacebookShare` depends upon `Bolts`, `FBSDKCoreKit`, and `FBSDKShareKit`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
The Swift pod `flutter_share_social_media` depends upon `Bolts`, `FBSDKCoreKit`, and `FBSDKShareKit`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/installer/xcode/target_validator.rb:135:in `verify_swift_pods_have_module_dependencies'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/installer/xcode/target_validator.rb:38:in `validate!'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:415:in `validate_targets'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:118:in `install!'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/command/install.rb:41:in `run'
/usr/local/lib/ruby/gems/2.5.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/command.rb:52:in `run'
/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
Error output from CocoaPods:
↳
[!] `<PBXGroup UUID=`97C146E51CF9000F007C117D`>` attempted to initialize an object with an unknown UUID. `CF3B75C9A7D2FA2A4C99F110` for attribute: `children`. This can be the result of a merge and the unknown UUID is being discarded.
[!] Automatically assigning platform `ios` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
【问题讨论】:
这个错误你解决了吗? 【参考方案1】:我遇到了类似的问题,输出相同 <PBXGroup UUID...
,就我而言,当我运行 pod install --verbose
时,我意识到 pod install
期间出现特定错误
#Dir:0x00007ff10befa7f0 的未定义方法 `each_child' 你的意思是?每个切片
在寻找这个特定错误时,我发现了这个answer,我意识到我使用的是 ruby 2.5,而 Flutter 为 iOS 设备生成的一个文件试图使用 2.6 版引入的方法。
按照该答案的步骤操作后,我可以在 iOS 模拟器上运行我的 Flutter 应用程序。
方法
dir.each_child
was introduced in Ruby 2.6,但是你使用的是Ruby 2.3.0。
你应该update Ruby 到 2.6.0 或更高的 2.x 版本。
在 Ruby 更新后,您可能还需要重新启动 IDE 和 re-install cocoapods。
【讨论】:
以上是关于使用 pod 依赖项创建 Flutter 插件的主要内容,如果未能解决你的问题,请参考以下文章
Flutter:Cocoapods 'Pods-Runner' 目标具有传递依赖项,包括静态二进制文件:Flutter.framework