本文由 简悦SimpRead 转码,原文地址 itnext.io
宣布cocoapods插件:cocoapods-embed-flutter,提供一种将flutter模块声明为t......。
宣布cocoapods插件。cocoapods-embed-flutter,提供一种在
Podfile中声明flutter模块为目标依赖的方法。
目前,如果你想在现有的iOS项目中集成一个flutter模块,你可以按照官方的指南。那么,你问为什么需要一个单独的插件呢?cocoapods-embed-flutter解决了官方解决方案的复杂性,同时使你的Podfile非常简单。
在官方解决方案中,你必须确保在运行 "pod install "之前,运行 "flutter pub get"。如果你的flutter模块和你的iOS项目不在同一个仓库里,那么你必须深入到git submodules。
解决方案?
如果你不熟悉 "Gemfile",我强烈建议你查看cocopods的指南,里面有很多深入的介绍。在本文的范围内,你可以在Gemfile中声明cocoapods-embed-flutter作为你的依赖项,像这样。
gem 'cocoapods-embed-flutter'
然后运行bundle install。另外,如果你不想使用Gemfile(尽管我强烈建议这样做),你可以使用sudo gem install cocoapods-embed-flutter来安装这个插件。
现在你都准备好了,在你的Podfile顶部添加cocoapods-embed-flutter作为一个插件。
plugin 'cocoapods-embed-flutter'
在这之后,对于任何目标,你可以用与pod相同的语法声明flutter模块的依赖性,将关键词pod替换为pub。要在本地使用一个名为my_cool_module的flutter模块,请使用。
target 'my_app' do
pub 'my_cool_module', :path => 'path/to/module'
end
这里:path可以直接指向pubspec.yaml文件或包含pubspec.yaml的目录。如果您的flutter模块与项目文件夹同名,那么您也可以提供flutter模块项目的父目录。
现在对于更复杂的情况,即flutter模块可能托管在外部git仓库,您可以使用。
target 'my_app' do
pub 'my_cool_module', :git => 'https://github.com/me/my_cool_module.git', :branch => 'dev'
pub 'flutter_module', :git => 'https://github.com/me/my_cool_module.git', :tag => '0.7.0'
pub 'flutter_module', :git => 'https://github.com/me/my_cool_module.git', :commit => '082f8319af'
end
从版本0.6开始,如果你的flutter模块项目不在你的仓库根目录下,你也可以在你的仓库中指定相对路径。
pub 'flutter_module', :git => 'https://github.com/me/my_cool_module.git', :tag => '0.7.0', :path => 'custom/path
您可以完全灵活地提供一个分支或标签,或在git源中使用一个特定的提交。在声明了所有的依赖关系后,你可以直接运行pod install,让cocoapods为你做所有的工作。对于更详细的例子或工作样本,请查看GitHub repo中的example应用程序。
链接
谢谢你的阅读! 希望这对你有帮助,如果你需要额外的功能或有一些建议,请参与GitHub repo。
DartBuild/cocoapods-embed-flutter: Cocoapods插件允许将flutter模块声明为依赖项(github.com)