Flutter项目自定义插件iOS平台引用.a静态库遇到的坑

Flutter自定义插件iOS集成.a库

说明

在flutter开发中有些第三方插件满足不了项目的开发需求,避免不了自己写自定义插件,关于自定义插件如何写,此处不再详细描述,今天会主要总结一下自定义插件iOS平台引用.a静态库遇到的问题。

.podspec文件

#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
  s.name             = 'flutter_bt_printer'
  s.version          = '0.0.2'
  s.summary          = 'A new Flutter plugin.'
  s.description      = <<-DESC
A new Flutter plugin.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.vendored_libraries = 'Classes/**/*.a'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.ios.deployment_target = '8.0'
end

1. 引用第三方库(.a文件)

s.dependency 'AFNetworking'

2. 引用三方静态库(.a文件)

s.vendored_libraries = 'Classes/xxx.a'

3. 当我们运行时,会报如下错误

ld: library not found for -lxxx
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这时候需要删除 flutter主工程的pods下对应的插件(要找到引用.a对应的插件)的TARGETS–>Build Settings->Other Linker Flags列表中的-l"XXX" 选项,再run一下还是报警告报错,内容如下:

Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_LPAPI", referenced from:
   objc-class-ref in Printermanager.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

说明 Printermanager文件引用了xxx.a的头文件。
这时候我们需要TARGETS–>Build Phases–>Compile Sources 删除xxx.a在Compile Sources同级的另一个选项Link Binary With Libraries 里添加刚刚删除的xxx.a文件。

4.Other Linker Flags配置

还要根据引用.a静态库的提示是否要在插件的TARGETS–>Build Settings->Other Linker Flags列表中加入-ObjC或-all_load等其他flag.

5.运行

最后 run 运行,如果不成功或如果上述步骤出错可以使用pod install重置设置选项。

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lester_ge

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值