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

Flutter问题记录 - 适配Xcode 16和iOS 18

文章目录

  • 前言
  • 开发环境
  • 问题及解决方案
    • 1. Upload Symbols Failed
    • 2. type 'UIApplication' does not conform to protocol 'Launcher'
    • 3. method does not override any method from its superclass
  • 最后


前言

为了新的镜像功能升级了macOS 15和iOS 18,Xcode也不可避免的需要升级到Xcode 16,老版本没办法在新系统上使用。每次大版本升级,带来新功能的同时也会带来一些问题,需要去适配去修复。

但有一说一,这个镜像功能真好用,声音/通知都会转发到电脑上,最重要的是,真机调试可以直接在电脑上操作,无需拿起手机

开发环境

  • Flutter: 3.22.3
  • Xcode: 16.0
  • iOS: 18.0

问题及解决方案

1. Upload Symbols Failed

项目打包上传到AppStore出现如下警告提示:
screenshot1

看提示是缺少符号文件。这个问题已经修复了,相关issuePR如下:

  • Flutter application missing framework dSYMs, validation error “The archive did not include a dSYM for the Flutter.framework with the UUIDs”
  • [iOS] Bundle dSYM packages in Flutter.xcframework

可以将Flutter升级到当前最新版本3.24.3解决该问题。不过,由于该版本的字体渲染有问题,所以我还是继续降级使用,毕竟只是个警告,目前暂时还不影响提交上架。

2. type ‘UIApplication’ does not conform to protocol ‘Launcher’

这是关于url_launcher库的报错:

.../url_launcher_ios-6.3.0/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift:22:1: error: type 'UIApplication' does not conform to protocol 'Launcher'
extension UIApplication: Launcher {}
^
UIKit.UIApplication:24:15: note: candidate has non-matching type '(URL, [UIApplication.OpenExternalURLOptionsKey : Any], (@MainActor @Sendable (Bool) -> Void)?) -> Void'
    open func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any] = [:], completionHandler completion: (@MainActor @Sendable (Bool) -> Void)? = nil)
              ^
.../url_launcher_ios-6.3.0/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift:15:8: note: protocol requires function 'open(_:options:completionHandler:)' with type '(URL, [UIApplication.OpenExternalURLOptionsKey : Any], ((Bool) -> Void)?) -> ()'; add a stub for conformance
  func open(
       ^

结合源码,可知问题出在了Launcher协议中的open方法,UIApplicationopen方法新增了@MainActor@Sendable修饰,导致方法签名不匹配报错。

目前通过定义新包装类DefaultLauncher的方式,修复了该问题,详情请看:

  • [ios]Fix compile error when conforming UIApplication to Launcher due to MainActor annotation

除了定义新包装类的方式,Launcher协议中的open方法增加@MainActor@Sendable修饰应该也能修复问题。

按理说,升级项目中的url_launcher库后该问题应该就解决了,但是针对这个问题,url_launcher库并没有发布新版本,只有它所依赖的url_launcher_ios库发布了6.3.1新版本。你可以参考以下两种方法解决这个问题:

  1. 修改pubspec.lock文件:
url_launcher_ios:
  dependency: transitive
  description:
    name: url_launcher_ios
    sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e
    url: "https://pub.flutter-io.cn"
  source: hosted
  version: "6.3.0"

删除sha256这一行以及将version改为6.3.1,然后重新运行pub get

  1. 修改pubspec.yaml文件:
dependency_overrides:
  url_launcher_ios: ^6.3.1

增加以上内容,强制指定url_launcher_ios库的版本。

3. method does not override any method from its superclass

这是关于flutter_inappwebview库的报错(截取部分):

.../flutter_inappwebview_ios-1.0.13/ios/Classes/InAppWebView/InAppWebView.swift:1432:26: error: method does not override any method from its superclass
    public override func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((Any?, Error?) -> Void)? = nil) {
                         ^
WebKit.WKWebView:46:26: note: potential overridden instance method 'evaluateJavaScript(_:completionHandler:)' here
    @MainActor open func evaluateJavaScript(_ javaScriptString: String, completionHandler: (@MainActor @Sendable (Any?, (any Error)?) -> Void)? = nil)
                         ^

.../flutter_inappwebview_ios-1.0.13/ios/Classes/InAppWebView/InAppWebView.swift:1036:21: error: ambiguous use of 'evaluateJavaScript(_:completionHandler:)'
                    evaluateJavaScript(NOT_ENABLE_VIEWPORT_SCALE_JS_SOURCE)
                    ^

这错误看上去和第二个问题很像,没错,又是因为方法增加了@MainActor@Sendable修饰导致的。该问题已经通过增加@MainActor@Sendable修饰的方式修复了,详情请看:

  • Fixed Xcode 16 build failed error: method does not override any method from its superclass

flutter_inappwebview库新版本发布前可以先通过以下方式解决:

dependency_overrides:
  flutter_inappwebview_ios:
    git:
      url: https://github.com/andychucs/flutter_inappwebview.git
      ref: master
      path: flutter_inappwebview_ios

pubspec.yaml文件中增加以上内容,强制指定flutter_inappwebview_ios库的来源。

最后

如果这篇文章对你有所帮助,点赞👍收藏🌟支持一下吧,谢谢~


本篇文章由@crasowas发布于CSDN。


http://www.kler.cn/news/310374.html

相关文章:

  • 【系统架构设计师-2011年真题】案例分析-答案及详解
  • 优思学院|如何从零开始自己学习六西格玛?
  • 井盖状态检测数据集
  • TCP socket
  • Android 进程间通信
  • 使用llama.cpp 在推理MiniCPM-1.2B模型
  • 24年蓝桥杯及攻防世界赛题-MISC-3
  • 【Redis】Redis 典型应用 - 分布式锁原理与实现
  • 计算机毕业设计 基于SpringBoot框架的网上蛋糕销售系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • Python编程 - 协程
  • [PICO VR眼镜]眼动追踪串流Unity开发与使用方法,眼动追踪打包报错问题解决(Eye Tracking/手势跟踪)
  • FFmpeg源码:skip_bits、skip_bits1、show_bits函数分析
  • centos远程桌面连接windows
  • iPhone 16系列:熟悉的味道,全新的体验
  • 浅谈Tair缓存的三种存储引擎MDB、LDB、RDB
  • 使用Addressables+SpriteAtlas打包产生冗余
  • Python知识点:详细讲解Python字节码与反编译
  • Elasticsearch 开放推理 API 新增阿里云 AI 搜索支持
  • react 高阶组件
  • 优化数据的抓取规则:减少无效请求
  • 【数学建模】典型相关分析
  • 【RabbitMQ 项目】服务端:数据管理模块之消息管理
  • 大语言模型超参数调优:开启 AI 潜能的钥匙
  • Linux下rpm方式部署mysql(国产化生产环境无联网服务器部署实操)
  • Android开发高频面试题之——Android篇
  • 为什么 ECB 模式不安全
  • ETL架构类型有哪些?怎么选择?
  • 力扣之1075.项目员工I
  • Java 垃圾收集器详解:CMS, G1, ZGC
  • 国产服务器CPU发展分析