当前位置: 首页 > news >正文

Flutter插件ios_pod

Flutter创建插件的命令

创建插件的命令flutter create --org com.plugin.demo --template=plugin --platforms=android,ios -i swift -a java plugin_demo

OC引用swift 文件

.m文件中添加以下代码//以下代码实现OC调用Swift
#if __has_include(<plugin_demo/plugin_demo-Swift.h>)#import <plugin_demo/plugin_demo-Swift.h>
#else// Support project import fallback if the generated compatibility header// is not copied when this plugin is created as a library.// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816#import "plugin_demo-Swift.h"
#endif

IOS插件plugin_demo.podspec配置


当对.podspec文件进行修改后,需要对项目执行pod install才有效#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint plugin_demo.podspec` to validate before publishing.
#
Pod::Spec.new do |s|s.name             = 'plugin_demo's.version          = '0.0.1's.summary          = 'A new Flutter plugin project.'s.description      = <<-DESC
A new Flutter plugin project.DESCs.homepage         = 'http://example.com's.license          = { :file => '../LICENSE' }s.author           = { 'Your Company' => 'email@example.com' }s.source           = { :path => '.' }#s.source_files = 'Classes/**/*'#指定包含的源文件类型,但是插件中用到的.metallib,.tflite,.mbd文件放置在pod所在的文件夹下不能正常#引用,需要放到主项目中s.source_files = ['Classes/**/*.{swift,h,m,mm,framework,tflite,bmd,metallib}']s.dependency 'Flutter's.platform = :ios, '12.0'# 指定桥接头文件路径,实现swift文件能访问oc文件s.user_target_xcconfig = {'SWIFT_OBJC_BRIDGING_HEADER' => '${PODS_ROOT}/../.symlinks/plugins/plugin_demo/ios/Classes/plugin_demo-Bridging-Header.h'}
#指定用到的其他.frameworks.vendored_frameworks = "*.framework"#指定用到的系统frameworks.frameworks = "AppTrackingTransparency"#PODS_TARGET_SRCROOT =# Flutter.framework does not contain a i386 slice.s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }s.swift_version = '5.0'# If your plugin requires a privacy manifest, for example if it uses any# required reason APIs, update the PrivacyInfo.xcprivacy file to describe your# plugin's privacy impact, and then uncomment this line. For more information,# see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files# s.resource_bundles = {'plugin_demo_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
end

官方文档

https://guides.cocoapods.org/syntax/podspec.html

以下配置来源于网上

   s.ios.source_files = 'PoCSDK/Classes/**/*','PoCSDK/Frameworks/Sinch.frameworks/Headers/*'#引用的第三方frameworks.ios.vendored_frameworks = 'PoCSDK/Sinch.framework'#配置头文件s.ios.public_header_files = 'PoCSDK/Frameworks/Sinch.frameworks/Headers/*'s.resource_bundles = {'NoddsSDK' => ['PoCSDK/Assets/*']}#指定项目中用到的系统库s.frameworks = 'UIKit', 'MapKit', 'AudioToolbox', 'AVFoundation's.ios.dependency 'Alamofire', '~> 4.5's.ios.dependency 'Socket.IO-Client-Swift's.ios.dependency 'ReachabilitySwift'

其它问题

当在.podspec文件中通过s.vendored_frameworks 配置了引用的第三方framework,但是build时依然编译不过
出现找不到对应的文件时,如 
iOS Undefined symbol: _OBJC_CLASS_$_XXXXXX , _OBJC_CLASS_$_XXX", referenced from:        in XXX.o  
解决方法:
1.点击Pods 在TARGETS 找到对应的插件。
2.切换到General -> Frameworks and Libraries 中点击加号+选择。
3.选择在插件目录中用到的framework.
3.视情况看是否对Framework标记为 Embed & Sign
http://www.dtcms.com/a/262957.html

相关文章:

  • httpd-devel 与服务无关
  • Java历史:从橡树到火星探索,从微软法律战到Spring、Gradle
  • [6-02-01].第05节:配置文件 - 读取配置文件的内容
  • 一、(基础)构建一个简单的 LangChain 应用
  • 对称非对称加密,https和http,https通讯原理,Charles抓包原理
  • macos 使用 vllm 启动模型
  • WIFI 低功耗保活知识系列---三.WiFi AP如何广播自己的缓存区信息
  • OpenCV CUDA模块设备层----计算向量的平方根函数sqrt
  • 基于Spring Boot的绿园社区团购系统的设计与实现
  • Python 安装使用教程
  • Spring Boot 启动性能优化实战指南
  • 基于 SpringBoot+Vue.js+ElementUI 的 Cosplay 论坛设计与实现7000字论文
  • 【硬核数学】2.7 理论与现实的鸿沟:深度学习的数值稳定性挑战《从零构建机器学习、深度学习到LLM的数学认知》
  • 【Spring】——事务、整合、注解
  • 后台管理系统模板Art Design Pro
  • js代码03
  • Karmada 多集群服务发现
  • Apache Doris Profile 深度解析:从获取到分析,解锁查询性能优化密码
  • RedhatCentos挂载镜像
  • LeetCode Hot100(图论)
  • SQL参数化查询:防注入与计划缓存的双重优势
  • 使用 Sqlcmd 高效导入大型 SQL Server 数据库脚本 (.sql)
  • 深入理解 B+ 树:数据库索引的脊梁
  • AI初学者如何对大模型进行微调?——零基础保姆级实战指南
  • vscode一个文件夹有残余的git仓库文件,已经失效了,怎样进行清空仓库残余文件并重新初始化git--ubuntu
  • 【stm32】HAL库开发——CubeMX配置RTC,单片机工作模式和看门狗
  • 炸鸡派-基础测试例程
  • Linux入门篇学习——Ubuntu 系统介绍和Ubuntu启用root用户
  • 在线五子棋对战项目
  • 1.1_2 计算机网络的组成和功能