在 Flutter 插件中使用 Git Submodule 給 Podspec 添加 fork 的第三方庫

目錄結(jié)構(gòu)示例

/path/to/your/flutter_plugin
├── .git
├── example
│   ├── ios
│   │   ├── Podfile
│   │   ├── Runner.xcodeproj
│   │   ├── Runner.xcworkspace
│   │   └── ...
│   └── lib
│       └── main.dart
├── ios
│   ├── Classes
│   │   └── ...
│   ├── your_plugin.podspec
└── lib
    └── your_plugin.dart

具體操作步驟如下

1.在 Flutter 插件目錄中添加 Git Submodule
  • 首先,導航到你的 Flutter 插件的 iOS 目錄,然后添加你 fork 的第三方庫作為 Git Submodule
cd /path/to/your/flutter_plugin/ios
git submodule add https://github.com/yourname/Charts.git Vendor/Charts
git submodule update --init --recursive
2.更新 Podspec 文件
  • 在你的 Flutter插件的 iOS 目錄中找到并編輯 Podspec 文件(通常是 your_plugin.podspec)。
# your_plugin.podspec
Pod::Spec.new do |s|
  s.name         = 'your_plugin'
  s.version      = '1.0.0'
  s.summary      = 'A short description of your_plugin.'
  s.description  = <<-DESC
                   A longer description of your_plugin in multiple lines.
                   DESC
  s.homepage     = 'http://example.com/your_plugin'
  s.license      = { :type => 'MIT', :file => 'LICENSE' }
  s.author       = { 'Your Name' => 'your.email@example.com' }
  s.source       = { :git => 'https://github.com/yourname/your_plugin.git', :tag => s.version.to_s }

  s.ios.deployment_target = '9.0'
  s.source_files  = 'Classes/**/*'

  # Adding the forked third-party library as a submodule
  s.subspec 'Charts' do |forked|
    forked.source_files = 'Vendor/Charts/**/*.{h,m,swift}'
  end
end
3.運行 pod install
  • example 項目的 iOS 目錄下運行 pod install。
cd /path/to/your/flutter_plugin/example/ios
pod install

更新完成后的目錄結(jié)構(gòu)示例

  • 最終,你的 Flutter 插件目錄結(jié)構(gòu)可能如下所示:
/path/to/your/flutter_plugin
├── .git
├── .gitmodules
├── example
│   ├── ios
│   │   ├── Podfile
│   │   ├── Runner.xcodeproj
│   │   ├── Runner.xcworkspace
│   │   └── ...
│   └── lib
│       └── main.dart
├── ios
│   ├── .gitmodules
│   ├── Classes
│   │   └── ...
│   ├── your_plugin.podspec
│   └── Vendor
│       └── Charts
│           ├── .git
│           ├── SourceFiles
│           └── ...
└── lib
    └── your_plugin.dart
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容