如何在Xcode中使用Flutter Flavors [英] How do you use Flutter Flavors in Xcode

查看:937
本文介绍了如何在Xcode中使用Flutter Flavors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个要为iOS构建的现有项目(两万行代码)(该项目已使用Android开发和测试,尽管我确实检查了它依赖的每个软件包都表明对iOS的支持。)

I have an existing project (20k lines of code) that I now want to build for iOS (The project has been developed and tested using Android, though I did check that every package it depends on indicates iOS support.)

我是Mac的新手(花了我一段时间才弄清楚如何通过GUI启动应用程序),但我设法通过了MacOS的Flutter设置指南

I'm completely new to Mac (It took me a while to figure out how even to launch apps via the GUI) but I managed to work through the Flutter setup guides for MacOS.

Flutter医生显示一切正常,到目前为止,Sample Flutter应用程序可以在Xcode iPhone模拟器上运行。

Flutter doctor shows all OK and so far the Sample Flutter app can run on the Xcode iPhone simulator.

该应用在构建或启动时需要具有特定的风格-在android方面,我拥有dev,qa和prod,它们分别具有完整和免费的功能,即6

The app needs to have a flavor specified when built or launched, - on the android side I have dev, qa, and prod, each with full and free, ie 6 flavors in total and separate entry points.

现在,当我尝试从Android Studio在模拟器上运行应用程序时,出现错误

Right now when I try to Run the app on the simulator from Android Studio, I get the error


Xcode项目未定义自定义方案。

您不能使用--flavor选项。

无法生成

在iPhone 11 Pro Max上启动应用程序时出错。

The Xcode project does not define custom schemes.
You cannot use the --flavor option.
Could not build the application for the simulator.
Error launching the application on iPhone 11 Pro Max.

在android方面,我使用了多个src目录结构以及AndroidManifest文件和单独的mipmap资源目录,以及用于切换资产的脚本-根据口味捆扎。每种口味都指定一个特定的main-*。dart入口点/目标,并且还有一系列与这些口味相对应的googleservices.json文件。

On the android side I use multiple src directory structures with AndroidManifest files and separate mipmap resource directories, plus a script to switch the asset-bundle based on the flavor. The Flavors each specifies a specific main-*.dart entry point / target and there are a series of googleservices.json files also corresponding to the flavors.

我现在需要一个将所有内容转换为xcode的方法-我收集到它称为 Schemas。我搜集到了我需要一个工具来设置架构(如果失败,则需要一个脚本来在构建过程中设置每个风味的部件)。还是他们称为跑步者资料?

I now need a way to translate all of that to xcode - I gather that it is called "Schemas". I gather I need a tool to set up the schemas (and where that fails, a script to set up per-flavor parts during the build process). Or are they called Runner Profiles?

我的问题是这个工具在哪里。有命令行版本吗?我可以以某种方式启动Xcode GUI并为生活在Android Studio中的项目设置模式吗?一旦我真正看到它的样子,许多博客中使用的许多术语可能就会变得很清楚。

My question is where is this tool. Is there a command-line version? Can I somehow launch the Xcode GUI and set up Schemas for a project that lives in Android Studio? A lot of the terminology used in the many blogs that cover this will probably become clear once I can actually see what it looks like.

一旦我有了适当的工具,我从阅读其他人的问题中意识到,下一个障碍将是要使iOS版本通过,需要进行特定的设置/调整,我认为这与某些软件包有关,但是现在我仍在研究

Once I have the tooling in place I realise from reading other people's questions that the next hurdle will be to see where specific setup/tweaking is required to get the iOS build to pass, I gather this is particularly an issue with some packages, but for now I'm still working out the tooling.

可能与我的下一个障碍有关,或者可能与工具设置不完整有关,当我尝试在未指定任何风格的情况下在模拟器上运行应用程序时,它告诉我Xcode构建已完成,并且该应用已安装在模拟器上,但由于堆栈跟踪而失败。我的猜测是,它告诉我它没有googleservices.json文件(一旦激活了正确的样式,则应在设置了正确的(googleservices-plist.info?)文件后将其整理出来-但在何处以及

Possibly related to "my next hurdle", or possibly related to incomplete tooling setup, when I try to run the app on the Simulator without any flavor specified, it tells me that the Xcode build completes and the app is installed on the simulator, but it fails with a Stack trace. My guess is that it is telling me that it doesn't have a googleservices.json file (which should be sorted out once the correct (googleservices-plist.info?) file is set, based on the flavor is activated - but where and how is this done?)

这也可能是由于权限甚至程序包错误引起的。

It could also be due to permissions, or even package errors.

编辑:调用堆栈涉及FIRapp配置和FLFirebaseMessagingPlugin registerWithRegistrar。这提示缺少的googleservices配置显然尚不可用-因为它是特定于口味的,因此我需要进行设置。

The call stack refers to FIRapp configure and FLFirebaseMessagingPlugin registerWithRegistrar. This hints at the missing googleservices config that is obviously not yet available - since it is flavor specific and I need to set that up.

一些针对性/特定的问题:

1. flutter运行和flutterbuild是否将 flavor参数作为xcode的方案名称传递?我认为答案是肯定的,否则就需要在某个地方进行映射。

2.如何为xcode中的每种样式设置方案(要知道项目在Android Studio中这一事实) )。

3. AndroidManifest.xml的iOS等效项是什么,专门用于指定applicationID和Launcher图标以及应用程序标签

4.如何分别指定- iOS的模式(按风味)googleservices.json文件?

5.如何/在何处设置按模式启动器图标?

Some pointed/specific questions:
1. Does flutter run and flutterbuild pass the "flavor" parameter as the name of a scheme to xcode? I would assume the answer is yes, else there needs to be a mapping somewhere.
2. How do I set up schemes for every flavor in xcode (with cognisance for the fact that the project is in Android Studio).
3. What is the iOS equivalent for the AndroidManifest.xml, specifically for specifying the applicationID and Launcher Icon and Application "Label"
4. How does one specify per-Schema (per flavor) googleservices.json files for iOS?
5. How / where does one set per-schema launcher icons?

我想我可以通过使用一个脚本替换掉默认模式文件的脚本来完成上述所有工作,该脚本使用一组指定为味道的文件-这是我使用的策略,因为Flutter Flavours不会扩展到资产或pubspec.yaml文件中设置的任何内容-但是我更喜欢使用受支持的工具,而不是破解解决方案。

I guess I could do all of the above by having a script that replaces the "default schema" files using a set of files beloning to a specified "flavor" - this is the strategy I use because Flutter Flavors doesn't extend to the assets or for that matter anything set in the pubspec.yaml file - but I prefer to use supported tools as far as possible over hackish solutions.

推荐答案

删除.idea目录并重新启动Android Stdio修复了我的环境中的相同问题。

Removing .idea directory and restart Android Stdio fixed the same issue on my environment.

这篇关于如何在Xcode中使用Flutter Flavors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆