Flutter:退出应用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter:退出应用相关的知识,希望对你有一定的参考价值。

参考技术A -此退出方式适用于Flutter是作为Model方式,存在于原生(例如android)项目里面,并且,当退出时,需要通知原生项目,原生有需要处理的业务,由原生项目来处理结束整个应用(例如Android的:System.exit(0);)

此退出方式就适合原生项目退出时没有需要处理的业务逻辑,直接就结束应用

Flutter documentation 上关乎 exit() 是这么说的:

无法在 iOS 模拟器上运行 Flutter 应用程序 / 命令 PhaseScriptExecution 失败,退出代码为非零

【中文标题】无法在 iOS 模拟器上运行 Flutter 应用程序 / 命令 PhaseScriptExecution 失败,退出代码为非零【英文标题】:cannot run Flutter application on iOS simulator / Command PhaseScriptExecution failed with a nonzero exit code 【发布时间】:2022-01-10 20:28:47 【问题描述】:

enter image description here enter image description here

加法如下

我制作 Flutter 应用程序。然后最近它碰巧无法在iOS模拟器上运行应用程序。我猜是Xcode升级的原因,但不太清楚。

你有什么想法可以帮助它吗?谢谢。

// 环境 //

PC:2021 Macbook air(苹果硅) MacOS:12.0.1 - 最近更新 Visual Studio 代码:1.62.3 Xcode:13.0 - 最近更新 颤振:2.5.3

// 完成 //

重启 PC & Xcode & Vscode 刷新钥匙串 列表项

删除派生数据

//扑医生//


flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale ja-JP)
    • Flutter version 2.5.3 at /Users/osanaidaisuke/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (7 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/osanaidaisuke/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A233
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.62.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (2 available)
    • iPhone 12 Pro (mobile) • B2A1F8F1-D8D0-41D4-B58F-B3AC18E0E3CE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 96.0.4664.55

• No issues found!

// 调试控制台 //


Launching lib/main.dart on iPhone 12 Pro in debug mode...
lib/main.dart:1
Xcode build done.                                            3.8s
Failed to build iOS app
Error output from Xcode build:
↳
    --- xcodebuild: WARNING: Using the first of multiple matching destinations:
     platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device 
     platform:iOS Simulator, id:E4530DD9-3EEB-4DFF-895E-2284A8BE131C, OS:15.0, name:iPad (9th generation) 
     platform:iOS Simulator, id:C9AEED53-CAAE-4357-9507-508EA93199C8, OS:15.0, name:iPad Air (4th generation) 
     platform:iOS Simulator, id:BE2B5D9F-C78E-4BE6-8720-66D6B37A7DBB, OS:15.0, name:iPad Pro (9.7-inch) 
     platform:iOS Simulator, id:FA89C5C9-39C1-4F00-91CA-45924F0484C3, OS:15.0, name:iPad Pro (11-inch) (3rd generation) 
     platform:iOS Simulator, id:2A37CCE9-6BA7-4BB9-9430-DB5EBCBE8D3E, OS:15.0, name:iPad Pro (12.9-inch) (5th generation) 
     platform:iOS Simulator, id:A641FC6E-451B-43CD-97AE-2427F4E71FC6, OS:15.0, name:iPad mini (6th generation) 
     platform:iOS Simulator, id:01C67389-E045-469F-88AF-4CE2980CE0B0, OS:15.0, name:iPhone 8 
     platform:iOS Simulator, id:D14130F2-B8BE-4FC2-8F99-537686236900, OS:15.0, name:iPhone 8 Plus 
     platform:iOS Simulator, id:6DE2DBDC-6BB8-41FF-A7EA-122E06ED3D09, OS:15.0, name:iPhone 11 
     platform:iOS Simulator, id:7FFC4095-7D08-4353-81CD-957F563FAF6A, OS:15.0, name:iPhone 11 Pro 
     platform:iOS Simulator, id:D397D581-E8C0-4EC4-BFE5-F05161D28A32, OS:15.0, name:iPhone 11 Pro Max 
     platform:iOS Simulator, id:055C8666-A3D5-4AF3-B52C-1F67909F3876, OS:15.0, name:iPhone 12 
     platform:iOS Simulator, id:B2A1F8F1-D8D0-41D4-B58F-B3AC18E0E3CE, OS:15.0, name:iPhone 12 Pro 
     platform:iOS Simulator, id:EEBEE112-736C-4D00-AEDC-7E4874390DB5, OS:15.0, name:iPhone 12 Pro Max 
     platform:iOS Simulator, id:CB3FC6AE-A5A7-4973-A758-8D86ABAD2CEE, OS:15.0, name:iPhone 12 mini 
     platform:iOS Simulator, id:659B04AA-DF4B-405E-B926-4FED18271CDD, OS:15.0, name:iPhone 13 
     platform:iOS Simulator, id:DFF4E533-9009-43D9-B905-7CC12C765C4E, OS:15.0, name:iPhone 13 Pro 
     platform:iOS Simulator, id:AF7C323B-3BF0-4BAB-9F6B-1C7DFA62DB41, OS:15.0, name:iPhone 13 Pro Max 
     platform:iOS Simulator, id:37DEFCE1-2E9E-42BB-91FE-93D0C7C92203, OS:15.0, name:iPhone 13 mini 
     platform:iOS Simulator, id:55EA657F-A586-4634-95D7-75B26B73DFC4, OS:15.0, name:iPhone SE (2nd generation) 
     platform:iOS Simulator, id:ACA87D06-CF69-490F-9DE7-12989F10CB62, OS:15.0, name:iPod touch (7th generation) 
     platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-0003452226EA001E 
     platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device 
    ** BUILD FAILED **
Xcode's output:
↳
    Failed to package /Users/osanaidaisuke/code/project-name/listview.
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Planning
    note: Build preparation complete

加法

每个项目文件都没有 Podsfile。这是正常的吗?而且我无法安装 cocoapods。

/ sudo gem install cocoapods //

Password:
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20211205-49831-16satjc.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=$opt-dir/include
        --with-opt-lib
        --without-opt-lib=$opt-dir/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
        --with-ffi_c-dir
        --without-ffi_c-dir
        --with-ffi_c-include
        --without-ffi_c-include=$ffi_c-dir/include
        --with-ffi_c-lib
        --without-ffi_c-lib=$ffi_c-dir/lib
        --enable-system-libffi
        --disable-system-libffi
        --with-libffi-config
        --without-libffi-config
        --with-pkg-config
        --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
        from extconf.rb:9:in `system_libffi_usable?'
        from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.4/gem_make.out

【问题讨论】:

你试过这个***.com/a/68170472/13547175 我遇到了同样的问题。试试这个https://***.com/a/64993852/4470297 它对我有用 我无法正常安装 cocoapods。所以我安装了 -v1.8.4 cocoapods 。 但是 [sudo gem install ffi] 也不好用。 错误:安装 rails 时出错:错误:无法构建 gem 原生扩展。当前目录:/Library/Ruby/Gems/2.6.0/gems/websocket-driver-0.7.5/ext/websocket-driver /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -我 /Library/Ruby/Site/2.6.0 -r ./siteconf20211205-52216-g0o51d.rb extconf.rb 创建 Makefile 【参考方案1】:

已修复,我的情况是文件权限问题,由 Flutter 管理员提供帮助。 https://github.com/flutter/flutter/issues/94692

但是根本原因我认为是错误提示不明显, 您可以查看调查步骤以了解原因, 你可能会找到你的解决方案

【讨论】:

谢谢。我不知道flutter --verbose 命令。它可能会给我一些提示。 以下构建命令失败:PhaseScriptExecution Run\ Script /Users/myname/Library/Developer/Xcode/DerivedData/Runner-acctwqhdfcmkyphhyoedbuzbziun/Build/Intermediate s.noindex/Runner.build/Debug-iphonesimulator/ Runner.build/Script-9740EEB61CF901F6004384FC.sh(在项目“Runner”的目标“Runner”中)【参考方案2】:

尝试更新 pod,转到您的 ios 文件夹,运行 pod deintegrate,然后 运行“pod install”。如果这没有帮助,请运行 pod update 或 'pod repo update'。尝试找出哪个软件包有问题,并更改它们的版本。

【讨论】:

你的意思是 ios 文件夹是每个 Flutter 项目中的一个文件夹,对吧? 这个错误可能发生在任何项目上,包括新的 Flutter 项目。 是的,每个flutter项目里面都有ios文件夹。【参考方案3】:

通过将 Flutter --version 从 2.5.3 升级到 2.8.1 解决了这个问题。

来源网址:https://minpro.net/your-flutter-checkout-has-local-changes-that-would-be-erased-by-upgrading

【讨论】:

以上是关于Flutter:退出应用的主要内容,如果未能解决你的问题,请参考以下文章

退出应用时Flutter保存应用的状态(登录首页后应用从登录页面启动)

无法在 Android 12.0 中退出 Flutter 应用

命令 PhaseScriptExecution 失败,退出代码非零 [iOS/Flutter]

退出 Flutter 应用程序不会返回登录页面

Flutter - 用户从应用程序退出后如何擦除提供者数据?

Flutter - Gradle 任务 assembleRelease 失败,退出代码为 1