flutter 元数据_Flutter Fastlane技巧集中式项目元数据管理

这篇博客探讨了在Flutter项目中如何使用Fastlane进行集中式的元数据管理,提供了提高项目效率的实用技巧。
摘要由CSDN通过智能技术生成

flutter 元数据

Flutter:跨平台应用程序框架 (Flutter: a cross-platform app framework)

Flutter is a next-generation cross-platform (Android, iOS, Web, Desktop, etc) app framework from Google with native performance (unlike React Native which has a JS bridge).

Flutter是Google提供的具有本机性能的下一代跨平台(Android,iOS,Web,桌面等)应用程序框架(不同于具有JS桥的React Native)。

Fastlane:一个应用程序自动化框架 (Fastlane: an app automation framework)

Fastlane is a framework that helps automate uploading app package, changelog, screenshot, and many more useful items to marketplaces (e.g. Apple Appstore, Google Play Store).

Fastlane是一个框架,可帮助自动将应用程序包,更改日志,屏幕截图以及更多有用的项目上载到市场(例如Apple Appstore,Google Play商店)。

Fastlane针对Android / iOS,而非Flutter (Fastlane targets Android/iOS, not Flutter)

As Fastlane started before Flutter, Flutter was not part of its plan.

当Fastlane在Flutter之前开始时,Flutter并不是其计划的一部分。

Fortunately, Fastlane and Flutter play well together except a few metadata syncing issues.

幸运的是,除了一些元数据同步问题之外,Fastlane和Flutter可以很好地协同工作。

A typical Flutter project looks like the following:

一个典型的Flutter项目如下所示:

Image for post

To add Fastlane to a Flutter project, we need to add Fastlane to each individual sub-project:

要将Fastlane添加到Flutter项目中,我们需要将Fastlane添加到每个单独的子项目中:

Image for post

Although this approach works, it introduces an issue:

尽管此方法有效,但它引入了一个问题:

  • To make sure all platform has the same metadata (e.g. versioning information), Flutter defines all the metadata on the Flutter project level and pass down to sub-project level at compile time.

    为了确保所有平台具有相同的元数据(例如版本信息),Flutter在Flutter项目级别定义了所有元数据,并在编译时传递给子项目级别。
  • Fastlane, as part of a sub-project, has no direct access to the metadata defined on the Flutter project which is one level up.

    作为子项目的一部分,Fastlane无法直接访问Flutter项目(上一级)上定义的元数据。

For example, Fastlane requires a version code to identify the corresponding metadata (e.g. changelog, screenshot, etc) to upload, but it won’t have access to it due to the issue:

例如,Fastlane需要一个版本代码来标识要上传的相应元数据(例如,变更日志,屏幕截图等),但由于该问题,它无法访问它:

Image for post

As a result, many projects have to hard code a version in Fastlane script and manually sync with the Flutter project.

结果,许多项目必须使用Fastlane脚本对版本进行硬编码,并手动与Flutter项目同步。

Many experienced developers might have smelled danger already: when a number exists in two places, they will mismatch at some point, and the consequence is releasing an outdated app to the users. Whoops :(

许多经验丰富的开发人员可能已经闻到了危险:当两个地方存在一个数字时,它们有时会不匹配,结果是向用户发布了过时的应用程序。 哎呀:(

When I suddenly realize that I forgot to bump the version number right after merging a change :(
当我突然意识到合并变更后忘记了版本号时,:(

The resolution to the issue is straightforward: grant Fastlane access to Flutter project metadata.

解决问题的方法很简单:授予Fastlane访问Flutter项目元数据的权限。

Thanks to the flutter_version Fastlane plugin, we can achieve this within a couple of lines of code.

感谢flutter_version Fastlane插件,我们可以在几行代码中实现这一目标。

步骤1:将flutter_version插件列为依赖项 (Step 1: List flutter_version plugin as a dependency)

As a Fastlane convention, to add a plugin, we need to define it in a Pluginfile:

作为Fastlane约定,要添加插件,我们需要在Pluginfile定义它:

To make sure the plugin is functional, run bundle install after making the change in Pluginfile.

为确保插件正常运行, bundle installPluginfile进行更改后运行bundle install

步骤2:在Fastlane脚本中使用flutter_version插件 (Step 2: Use flutter_version plugin in Fastlane script)

After the plugin finishes installing, we can use futter_version in the Fastfile to access Flutter project metadata. For example, version information:

插件安装完成后,我们可以使用futter_version中的Fastfile访问Flutter项目元数据。 例如,版本信息:

Note: flutter_version supports an optional input pubspec_location that defines a custom location of Flutter project metadata file if not in a conventional Flutter project setup. Currently, flutter_version returns the version code and version name. If the version defined in pubspec.yaml is 1.0.6+15 , then the version_code is 15 and the version_name is 1.0.6.

注意: flutter_version支持可选的pubspec_location输入,如果不是在传统的Flutter项目设置中,则该输入定义了Flutter项目元数据文件的自定义位置。 当前, flutter_version返回版本代码和版本名称。 如果pubspec.yaml定义的版本为1.0.6+15 ,则version_code为15, version_name1.0.6

步骤3(可选):将Fastlane执行添加到工作流脚本 (Step 3 (optional): Add Fastlane execution to workflow script)

Since downloading packages from GitHub registry in CI/CD is a non-trivial setup, please use the following GitHub Action script as a starting point:

由于从CI / CD中的GitHub注册表中下载软件包是不平凡的设置,因此请使用以下GitHub Action脚本作为起点:

Thanks for reading and happy hacking!

感谢您的阅读和愉快的黑客入侵!

All kinds of contributions to the repository are appreciated. Let’s make cross-platform app developing experience better, together ;)

感谢对存储库的各种贡献。 让我们一起来改善跨平台应用程序的开发体验;)

翻译自: https://levelup.gitconnected.com/flutter-fastlane-tips-centralized-project-metadata-management-6de3fec21d37

flutter 元数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值