xcode Flutter - 为 iOS 构建,但链接和嵌入式框架“App.framework”是为 iOS 模拟器构建的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/60881764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:04:20  来源:igfitidea点击:

Flutter - Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator

xcodeandroid-studioflutterdart

提问by gordonturibamwe

After updating to Catalina 10.15.4 beta with Xcode 13.4 beta, which also updated Simulator to 13.4 (921.4).

在使用 Xcode 13.4 beta 更新到 Catalina 10.15.4 beta 之后,它也将 Simulator 更新到 13.4 (921.4)。

The application compiles and runs correctly on a physically attached device, but no simulators of any devices can pass this stage.

应用程序在物理连接的设备上编译并正确运行,但没有任何设备的模拟器可以通过这个阶段。

I got the errors

我得到了错误

Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.

为 iOS 构建,但链接和嵌入式框架“App.framework”是为 iOS 模拟器构建的。

or

或者

Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS.

为 iOS 模拟器构建,但链接和嵌入式框架“App.framework”是为 iOS 构建的。

enter image description here

在此处输入图片说明

How can I fix this?

我怎样才能解决这个问题?

回答by Lo?c Fonkam

Xcode 11.4 changed the way frameworks are linked and embedded, and you may experience issues switching between iOS devices and simulators. Flutter v1.15.3 and later will automatically migrate your Xcode project.

Xcode 11.4 改变了框架的链接和嵌入方式,您可能会在 iOS 设备和模拟器之间切换时遇到问题。Flutter v1.15.3 及更高版本将自动迁移您的 Xcode 项目。

To get unstuck, follow the instructions below;

要摆脱困境,请按照以下说明进行操作;

  • Quick fix(make your simulator work)
  • 快速修复(让你的模拟器工作)

rm -rf ios/Flutter/App.framework

rm -rf ios/Flutter/App.framework

  • Officialrecommended Steps to migrate manually

    1. From the Flutter app directory, open ios/Runner.xcworkspace in Xcode.
    2. In the Navigator pane, locate the Flutter group and remove App.framework and Flutter.framework. enter image description here
    3. In the Runner target build settings Build Phases > Link Binary With Libraries confirm App.framework and Flutter.framework are no longer present. Also confirm in Build Phases > Embed Frameworks.
  • 官方推荐的手动迁移步骤

    1. 在 Flutter 应用程序目录中,在 Xcode 中打开 ios/Runner.xcworkspace。
    2. 在 Navigator 窗格中,找到 Flutter 组并删除 App.framework 和 Flutter.framework。 在此处输入图片说明
    3. 在 Runner 目标构建设置 Build Phases > Link Binary With Libraries 中,确认 App.framework 和 Flutter.framework 不再存在。还要在 Build Phases > Embed Frameworks 中确认。

enter image description here

在此处输入图片说明

  1. Change the Runner target build settings Build Phases > Thin Binary script as follows:

    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed

    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" thin

  1. 更改 Runner 目标构建设置 Build Phases > Thin Binary script 如下:

    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" 嵌入

    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" 瘦

enter image description here

在此处输入图片说明

  1. In the Runner target Build Settings > Other Linker Flags

    (OTHER_LDFLAGS) add $(inherited) -framework Flutter

  1. 在 Runner 目标Build Settings > Other Linker Flags

    (OTHER_LDFLAGS) 添加 $(inherited) -framework Flutter

enter image description here

在此处输入图片说明

Hope it helps!

希望能帮助到你!

回答by Viktor K

Xcode 11.4 changed the way frameworks are linked and embedded, which is causing issues switching between iOS devices and simulators.

Xcode 11.4 改变了框架的链接和嵌入方式,这导致了 iOS 设备和模拟器之间切换的问题。

Please follow official guideon how to migrate your project.

请遵循有关如何迁移项目的官方指南

回答by gordonturibamwe

After several days trying to find a solution to test the Flutter app on iOS device, I finally found this:

经过几天试图找到在 iOS 设备上测试 Flutter 应用程序的解决方案,我终于找到了这个:

flutter clean
flutter build ios

-Open xCode and run app on your device.

- 打开 xCode 并在您的设备上运行应用程序。

回答by user12657834

Updated to Xcode 11.4. Ios 13.4, Iphone X. App just fetches data using API. App started on white screen and then finally crashes, both on simulator and device.

更新到 Xcode 11.4。Ios 13.4,Iphone X。App 只是使用 API 获取数据。应用程序在白屏上启动,然后最终在模拟器和设备上崩溃。

I followed the offical guide (I also rm -rf ios/Flutter/App.framework) flutter.dev/docs/development/ios-project-migration. I ran several times flutter clean

我遵循了官方指南(我也rm -rf ios/Flutter/App.frameworkflutter.dev/docs/development/ios-project-migration。我跑了几次flutter clean

I also tried deleting Pods/ folder and Podfile.lock, then reinstalling using pod installin the ios folder.

我还尝试删除 Pods/ 文件夹和 Podfile.lock,然后pod install在 ios 文件夹中重新安装。

As I am using async data I also added as 1st line in main()

当我使用异步数据时,我还在 main() 中添加了第一行

WidgetsFlutterBinding.ensureInitialized();

No help, app did not started either simulator.

没有帮助,应用程序没有启动任何模拟器。

Then I removed ios/and android/folders. After that in project folder I ran command flutter create .that regenerates mentioned folders.

然后我删除了ios/android/文件夹。之后在项目文件夹中我运行flutter create .了重新生成提到的文件夹的命令。

After this my app started fine both on simulator and on device. I hope this would be help to others. NOTE!! if you have done any modifications manually to those folders please take backup or commit beforehand.

在此之后,我的应用程序在模拟器和设备上都开始正常。我希望这会对其他人有所帮助。笔记!!如果您手动对这些文件夹进行了任何修改,请事先进行备份或提交。

回答by Phil Tran

I have tried the solution on the official website of flutter but it didn't work for me, so I found a temporary solution which worked for me, but it took me some hard works: Here is my example with project stuck_framework which is a fresh new project (first time run on the simulator)

我已经在 flutter 的官方网站上尝试了解决方案,但它对我不起作用,所以我找到了一个对我有用的临时解决方案,但我花了一些努力:这是我的项目卡住_框架的例子,这是一个新鲜的新项目(第一次在模拟器上运行)

  1. I created 2 folders inside flutter project called
    "ios_simulator" and "ios_real_device". enter image description here

  2. Now my first build was for the simulator, then I want to switch to a real device, I will move ios folder inside Flutter project to the "ios_simulator"

  3. I open the project with visual studio code and run "flutter create ." and now I will choose a real device to rebuild the project ( if your simulator is online, please quit ). enter image description here
  4. Now I wait for the build finish and run on the real device without any errors. Now I have 2 ios project 1 for simulators and one for real devices.
  5. Next time when I want to run on the simulator again, I just remove the current ios folder and copy the ios folder which I placed on "ios_simulator" back out to flutter project folder. Hope this help
  1. 我在 flutter 项目中创建了 2 个文件夹,名为
    “ios_simulator”和“ios_real_device”。 在此处输入图片说明

  2. 现在我的第一个构建是针对模拟器的,然后我想切换到真实设备,我将 Flutter 项目中的 ios 文件夹移动到“ios_simulator”

  3. 我使用 Visual Studio 代码打开项目并运行“flutter create”。现在我将选择一个真实的设备来重建项目(如果你的模拟器在线,请退出)。 在此处输入图片说明
  4. 现在我等待构建完成并在真实设备上运行而没有任何错误。现在我有 2 个 ios 项目,1 个用于模拟器,一个用于真实设备。
  5. 下次当我想再次在模拟器上运行时,我只需删除当前的 ios 文件夹并将我放在“ios_simulator”上的 ios 文件夹复制回 flutter 项目文件夹。希望这有帮助

回答by Johnny Vietnam

Manually upgrading flutter to version 1.15 solve this issue as well. Running flutter version v1.15.17helped me.

手动将 flutter 升级到 1.15 版本也可以解决这个问题。跑步flutter version v1.15.17帮助了我。

Also, you can switch to betaor devchannels by running flutter channelcommand but be sure you check your code against all BC changes...

此外,您可以通过运行命令切换到betadev频道,flutter channel但请确保根据所有 BC 更改检查您的代码...

回答by KIM

In my case, it works only simulator(debug). if you want to deploy your app on the app store(release) i highly recommend you to upgrade flutter version using

就我而言,它仅适用于模拟器(调试)。如果您想在应用商店(发布)上部署您的应用,我强烈建议您使用以下方法升级 Flutter 版本

flutter version v1.15.17

otherwise you would encounter crashed app with white screen.

否则你会遇到白屏崩溃的应用程序。

just upgrade flutter version then all things work well

只需升级颤振版本,然后一切正常