简体   繁体   English

在 Xcode 中如何使用 Flutter 口味

[英]How do you use Flutter Flavors in Xcode

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.) 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.)

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.我对 Mac 完全陌生(我花了一段时间才弄清楚如何通过 GUI 启动应用程序),但我设法完成了 MacOS 的 Flutter 设置指南。

Flutter doctor shows all OK and so far the Sample Flutter app can run on the Xcode iPhone simulator. Flutter 医生显示一切正常,到目前为止,示例 Flutter 应用程序可以在 Xcode iPhone 模拟器上运行。

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 方面,我有 dev、qa 和 prod,每个都有完整和免费的,即总共 6 个风格和单独的入口点。

Right now when I try to Run the app on the simulator from Android Studio, I get the error现在,当我尝试从 Android Studio 在模拟器上运行应用程序时,出现错误

The Xcode project does not define custom schemes. Xcode 项目未定义自定义方案。
You cannot use the --flavor option.您不能使用 --flavor 选项。
Could not build the application for the simulator.无法为模拟器构建应用程序。
Error launching the application on iPhone 11 Pro Max.在 iPhone 11 Pro Max 上启动应用程序时出错。

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.在 android 方面,我使用多个 src 目录结构和 AndroidManifest 文件和单独的 mipmap 资源目录,以及根据风格切换资产包的脚本。 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.每个风味都指定了一个特定的 main-*.dart 入口点/目标,并且还有一系列 googleservices.json 文件也对应于风味。

I now need a way to translate all of that to xcode - I gather that it is called "Schemas".我现在需要一种方法将所有这些转换为 xcode - 我认为它被称为“模式”。 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?或者它们被称为 Runner Profiles?

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?我可以以某种方式启动 Xcode GUI 并为 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.一旦我真正看到它的样子,许多博客中使用的许多术语可能会变得清晰。

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.一旦我有了工具,我从阅读其他人的问题中意识到,下一个障碍将是查看需要在哪里进行特定设置/调整才能使 iOS 构建通过,我认为这对于某些软件包来说尤其是一个问题,但是对于现在我还在研究工具。

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.可能与“我的下一个障碍”有关,或者可能与工具设置不完整有关,当我尝试在没有指定任何风格的情况下在模拟器上运行应用程序时,它告诉我 Xcode 构建完成并且应用程序已安装在模拟器上,但是它因堆栈跟踪而失败。 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?)我的猜测是它告诉我它没有 googleservices.json 文件(一旦设置了正确的(googleservices-plist.info?)文件,就应该根据风味被激活 - 但是在哪里和这是怎么做到的?)

It could also be due to permissions, or even package errors.这也可能是由于权限,甚至是 package 错误。

Edit: The call stack refers to FIRapp configure and FLFirebaseMessagingPlugin registerWithRegistrar.编辑:调用堆栈是指 FIRapp 配置和 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.这暗示了丢失的 googleservices 配置显然尚不可用 - 因为它是特定于风味的,我需要进行设置。

Some pointed/specific questions:一些尖锐/具体的问题:
1. Does flutter run and flutterbuild pass the "flavor" parameter as the name of a scheme to xcode? 1、flutter是否运行,flutterbuild是否将“flavor”参数作为scheme的名称传递给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). 2.如何在xcode中为每种风格设置方案(认识到该项目在Android Studio中)。
3. What is the iOS equivalent for the AndroidManifest.xml, specifically for specifying the applicationID and Launcher Icon and Application "Label" 3. AndroidManifest.xml 的 iOS 等效项是什么,专门用于指定 applicationID 和 Launcher Icon 和 Application "Label"
4. How does one specify per-Schema (per flavor) googleservices.json files for iOS? 4. 如何为 iOS 指定每个模式(每种风格)googleservices.json 文件?
5. How / where does one set per-schema launcher icons? 5. 如何/在哪里设置每个模式启动器图标?

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.我想我可以通过使用一组属于指定“风味”的文件替换“默认模式”文件的脚本来完成上述所有操作 - 这是我使用的策略,因为 Flutter 风味不会扩展到资产或者就此而言,在 pubspec.yaml 文件中设置的任何内容 - 但我更喜欢尽可能使用受支持的工具而不是骇人听闻的解决方案。

Removing.idea directory and restart Android Stdio fixed the same issue on my environment.删除.idea 目录并重新启动 Android Stdio 在我的环境中修复了相同的问题。

I faced the same issue.我遇到了同样的问题。 If you are using git, try to remove the source code folder and clone again.如果您使用的是 git,请尝试删除源代码文件夹并再次克隆。 Git caches something that prevent from building for iOS Git 缓存了阻止为 iOS 构建的内容

If you haven't set up flavor for iOS yet, following this part 3 tutorial如果您还没有为 iOS 设置风味,请按照第 3 部分教程进行操作

https://medium.com/@LohaniDamodar/flutter-separating-build-environment-with-multiple-firebase-environment-92e40e26d275 https://medium.com/@LohaniDamodar/flutter-separating-build-environment-with-multiple-firebase-environment-92e40e26d275

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM