京东技术中台的Flutter实践之路,深入分析

eval(File.read(File.join(flutter_application_path, ‘.ios’, ‘Flutter’, ‘podhelper.rb’)), binding)

安装pod

pod install

打开工程(***.xcworkspace) 配置build phase,为编译Dart 代码添加编译选项打开iOS项目,选中项目的Build Phases选项,点击左上角+号按钮,选择New Run Script Phase,将下面的shell脚本添加到输入框中:

“$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh” build

“$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh” embed

京东技术中台的Flutter实践之路,深入分析_第1张图片

搭建PUB私服仓库

Flutter开发中使用的组件,一般公司内部会采用共享的方式,以避免重复开发,而Flutter组件共享,即需要使用pub仓库。由于公司内部的业务组件不适合上传到pub官方仓库,因此,需要搭建私服仓库,以解决各个业务研发团队,对Flutter组件共享需要。感兴趣的同学可以研究下官方pub仓库的源码 http://pub.dartlang.org/,其对Google Cloud 环境有很大的依赖 , 也可以基于https://github.com/kahnsen/pub_server来搭建一个简易版本的私服仓库,以满足上传和下载功能,pub协议相对比较简单,我们可以在源码增加协议接口来实现更多功能。运行pub_server

~ $ git clone https://github.com/dart-lang/pub_server.git
$ cd pub_server

~/pub_server $ pub get

~/pub_server $ dart example/example.dart -d /tmp/package-db

Listening on http://localhost:8080

To make the pub client use this repository configure your shell via:

$ export PUB_HOSTED_URL=http://localhost:8080

发布一个Flutter组件需要修改 pubspec.yaml,增加以下内容:

name: hello_plugin //plugin名称

description: A new Flutter plugin. //介绍

version: 0.0.1//版本号

author: xxx [email protected]//作者和邮箱

homepage: https://localhost:8080 //组件的介绍页面

publish_to: http://localhost:8080//仓库上传地址

上传时可以使用如下命令检查代码错误,并显示出上传的目录结构。

pub publish --dry-run

如果有不想上传的文件,可以在根目录增加一个.gitignore文件来忽略如下:

/build

Flutter组件的依赖配置,在项目的pubspec.yaml中dependencies:下增加如下信息:

dependencies:

hello_plugin:

hosted:

name: hello_plugin

url: http://localhost:8080

version: 0.0.2

这样可以在公司内部实现

你可能感兴趣的:(程序员,架构,移动开发,android)