如何在Flutter中创建多个iOS目标? [英] How to make multiple iOS Targets in Flutter?

查看:428
本文介绍了如何在Flutter中创建多个iOS目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让Flutter为iOS运行另一个不是默认"Runner"的目标?

How can I make Flutter run a different Target for iOS that is not the default "Runner"?

推荐答案

这将非常棘手.如果查看flutter run --help命令的输出,将会看到它支持自定义的--flavor选项,该选项允许您指定自定义方案.

That's going to be tricky. If you look at the output of flutter run --help command, you will see that it supports a custom --flavor option that allows you to specify a custom scheme.

但是,要使其正常工作,需要做几件事:

However, several things need to be done in order to make it work:

  1. 在Xcode中打开工作区-在终端中从应用程序的根目录运行open ios/Runner.xcworkspace.

通过扩展项目和目标列表,单击Runner项目并选择Duplicate(

Clone the Runner target by expanding the project and target list, clicking on the Runner project and selecting Duplicate (more details here).

这也应该为您创建一个自定义方案,并使用其自己的Info.plist文件.该方案在默认情况下将称为Runner-copy,将其重命名为您命名的新目标(例如分段).

This should create a custom scheme for you as well, with its own Info.plist file. The scheme will be called Runner-copy by default, rename it to what you named your new target (e.g. Staging).

  1. 复制调试并发布构建配置,并按Flutter期望的命名方式来命名它们.例如,如果您的新目标称为"Staging",则需要创建一个"Debug-Staging"和"Release-Staging"构建配置(编辑Podfile并复制整个target 'Runner' do部分,将目标名称替换为您的名称.然后,运行pod install.

    Edit the Podfile and copy the entire target 'Runner' do section, replacing the name of the target with yours. Afterwards, run pod install.

    现在您有两个不同的目标,您可以执行一些操作,例如设置不同的捆绑软件ID或包含不同的文件.

    Now that you have two different targets, you can do things like set different bundle ids, or include different files.

    1. 从命令行运行您的自定义方案.例如:flutter run --flavor Staging.

    如果第5步失败,请手动重新运行pod install,在Xcode中打开工作区并从那里运行.

    If step #5 failed, re-run pod install manually, open the workspace in Xcode and run from there.

    注意:这非常脆弱,使用后果自负

    Note: this is pretty fragile, use at your own risk

    注意:我无法使其在发布模式下运行

    Note: I was not able to get this to run in release mode

    这篇关于如何在Flutter中创建多个iOS目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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