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重置设置选项。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
要在 Android Studio 中部署 Flutter 项目iOS 设备上,需要遵循以下步骤: 1. 在 Flutter 项目中打开终端,并运行 `flutter build ios` 命令,以构建 iOS 应用程序。 2. 在 iOS 设备上安装 Xcode,打开 Xcode 并选择 `File -> New -> Project` 菜单项。 3. 在弹出的菜单中,选择 `Application -> Single View Application`,并输入应用程序的名称和组织标识符。 4. 在 `Product` 菜单中选择 `Destination`,并选择要部署到的 iOS 设备。 5. 在 `File` 菜单中选择 `Add Files to "Project Name"`,并选择 Flutter 项目中的 `ios` 文件夹。 6. 在弹出的菜单中,选择 `Copy items if needed`,并点击 `Finish`。 7. 在 `AppDelegate.swift` 文件中,添加以下代码: ``` import UIKit import Flutter @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } ``` 8. 在 `Info.plist` 文件中,添加以下权限: ``` <key>NSCameraUsageDescription</key> <string>Camera Permission</string> <key>NSMicrophoneUsageDescription</key> <string>Microphone Permission</string> <key>NSPhotoLibraryUsageDescription</key> <string>Photo Library Permission</string> ``` 9. 在 Xcode 中,选择 `Product -> Build` 菜单项,以构建 iOS 应用程序。 以上就是在 Android Studio 中部署 Flutter 项目iOS 设备上的步骤。注意,在构建 iOS 应用程序之前,需要在 Mac 上安装并配置 Xcode 和 iOS 开发人员工具。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Lester_ge

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

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

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

打赏作者

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

抵扣说明:

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

余额充值