Skip to content

feat(ios): add Swift Package Manager support for iOS and macOS - #653

Closed
archie0732 wants to merge 1 commit into
dlutton:masterfrom
ExpTechTW:feat/swift-package-manager
Closed

feat(ios): add Swift Package Manager support for iOS and macOS#653
archie0732 wants to merge 1 commit into
dlutton:masterfrom
ExpTechTW:feat/swift-package-manager

Conversation

@archie0732

Copy link
Copy Markdown

移植上游 dlutton/flutter_tts#651(作者 @shivanshu877),為 iOS 與 macOS 加上 Swift Package Manager 支援。

用 cherry-pick 而不是重打一遍,所以 commit 的作者仍是原作者,內容與該 PR 一字不差(13 檔案 +62 −26)。該 PR 的 base 就是本 repo 的 masterad4a10bb),套用時沒有任何衝突。

為什麼要做

DPIP 的 iOS 端使用 Swift Package Manager,沒有 CocoaPods 的設定。flutter_tts 只提供 podspec,Flutter 每次建置都會警告:

The following plugins do not support Swift Package Manager for ios:
* flutter_tts
This will become an error in a future version of Flutter.

在那之前它會退回 CocoaPods,等於透過相依關係把一個 Podfile 悄悄帶回專案裡。

上游從 2026-05 起有三個功能相同的 PR(#631#634#651)都沒有被合併,所以在這個 fork 自行套用。

改了什麼

  • 新增 ios/flutter_tts/Package.swiftmacos/flutter_tts/Package.swift
  • Swift 原始碼從 Classes/ 搬到 SPM 版面配置 <platform>/flutter_tts/Sources/flutter_tts/
  • 刪除 iOS 的 Objective-C 註冊殼(FlutterTtsPlugin.h / .m):Swift 類別由 SwiftFlutterTtsPlugin 更名為 FlutterTtsPlugin,可直接對應 pubspec.yamlpluginClass,不再需要轉發
  • 兩個 podspec 的 source_files 改指新路徑;iOS deployment_target 8.0 → 12.0
  • CocoaPods 仍然可用,兩種整合方式並存

靜態檢查(Windows 上做得到的部分)

  • 全 repo 已無 SwiftFlutterTtsPlugin 的殘留參照
  • pubspec.yamlpluginClass: FlutterTtsPlugin 對得上兩個平台的 public class FlutterTtsPlugin,且各有一個 public static func register(with:)
  • Package.swift 的 package 名稱等於目錄名、product 用短橫線、target 用底線 —— 與 url_launcher_ios 等官方 plugin 的慣例一致
  • Sources/flutter_tts/ 底下確實有原始碼(iOS 4 個檔、macOS 1 個),podspec 的 glob 也指向該處
  • plugin 的最低版本(iOS 12.0)低於 DPIP 的 15.0,不會擋掉建置
  • Package.swift 中的 .package(name: "FlutterFramework", path: "../FlutterFramework")awesome_notificationsawesome_notifications_fcm 的寫法相同 —— DPIP 目前正在使用這兩個套件且 iOS CI 為綠,因此這個形式在專案釘選的 Flutter 3.47.0 上是可行的

沒有驗證的部分

沒有 macOS 環境,因此完全沒有實際建置過。 上面全部是靜態檢查,Package.swift 沒有被任何 Swift toolchain 解析過,iOS / macOS 都沒有跑過 flutter build

要合併之前,需要有 Mac 的人跑一次 example app(或直接在 DPIP 上以 git 相依指向這個分支試建)確認:

  1. flutter build ios 能通過,且不再出現 SPM 不支援的警告
  2. TTS 實際會出聲、speak 完成回呼正常
  3. CocoaPods 路徑沒有被這次的檔案搬移弄壞

想請你決定的一件事

該 commit 把 pubspec.yamlversion4.2.5 改成 4.3.0,但上游尚未發布 4.3.0。若日後上游發布內容不同的 4.3.0,兩者會混淆。

是否要改成 4.2.5+exptech.1 之類明確標示 fork 的形式?DPIP 以 git 相依取用,版本號不影響解析,所以純粹是標示上的取捨。我沒有自行更動,因為改了這則 commit 就不再等於上游 #651,審查時無法一眼比對。

另外注意(本次未動)

ios/flutter_tts.podspecs.swift_version = '4.2'Package.swiftswift-tools-version: 5.9 不一致。這是上游原本就有的狀態,#651 沒有處理,我也刻意不動,以保持這則 commit 與原 PR 相同。要修的話建議另開一則。

Migrates both Apple plugins to Swift Package Manager while keeping CocoaPods
working:

- iOS: move the Swift sources under ios/flutter_tts/Sources/flutter_tts, remove
  the Objective-C registration shim (FlutterTtsPlugin.h/.m) and rename
  SwiftFlutterTtsPlugin to FlutterTtsPlugin so the pubspec pluginClass is
  unchanged, matching the existing macOS implementation.
- macOS: move the Swift source under macos/flutter_tts/Sources/flutter_tts.
- Add ios/ and macos/ Package.swift (each depends on FlutterFramework).
- Update both podspecs' source_files to the new locations and drop the obsolete
  iOS public_header_files entry.

Verified: example builds for the iOS simulator and macOS under both Swift
Package Manager and CocoaPods.
@archie0732

Copy link
Copy Markdown
Author

Opened against the wrong base by mistake — this was meant for our own fork
(ExpTechTW/flutter_tts), not upstream. The commit is a cherry-pick of
@shivanshu877's #651 with no changes of my own, so there is nothing new here.

Closing; sorry for the noise. #651 is still the one worth reviewing.

@archie0732 archie0732 closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants