flutter项目无法在ios上运行

时间:2020-03-31 00:19:28

标签: ios xcode flutter

有一个以前正在运行的应用程序,该应用程序不再运行,而我一直在努力解决这一问题。现在已经到了几乎可以运行的地步,但是我遇到了最后一个障碍:

flutter run -v

这似乎可以成功构建并启动应用程序,屏幕短暂变为白色,然后关闭应用程序。终端输出的最后一个条目是:

[ +293 ms] ------ Debug phase ------
[        ] Starting debug of 53225g34b4c604fe43a334525340e269626a (D111AP,
iPhone 7 Plus, iphoneos, arm64) a.k.a. 'iPhone' connected through USB...
[ +935 ms] [  0%] Looking up developer disk image
[  +27 ms] [ 95%] Developer disk image mounted successfully
[ +367 ms] [100%] Connecting to remote debug server
[        ] -------------------------
[+1080 ms] (lldb) command source -s 0
'/tmp/1D186BA70/fruitstrap-lldb-prep-cmds-4c604fe43a334525340e269626a'
[        ] Executing commands in
'/tmp/1D186BA70/fruitstrap-lldb-prep-cmds-4c604fe43a334525340e269626a'
[        ] (lldb)     platform select remote-ios --sysroot
'/Users/sjr/Library/Developer/Xcode/iOS DeviceSupport/13.3.1 (17D50)/Symbols'
[        ]   Platform: remote-ios
[        ]  Connected: no
[        ]   SDK Path: "/Users/sjr/Library/Developer/Xcode/iOS
DeviceSupport/13.3.1 (17D50)/Symbols"
[        ] (lldb)     target create
"/Users/sjr/Projects/my_app/build/ios/iphoneos/Runner.app"
[+10050 ms] Current executable set to
'/Users/sjr/Projects/my_app/build/ios/iphoneos/Runner.app' (arm64).
[        ] (lldb)     script
fruitstrap_device_app="/private/var/containers/Bundle/Application/62B3E66E1/Runner.app"
[ +443 ms] (lldb)     script fruitstrap_connect_url="connect://127.0.0.1:49422"
[        ] (lldb)     script fruitstrap_output_path=""
[        ] (lldb)     script fruitstrap_error_path=""
[        ] (lldb)     target modules search-paths add /usr
"/Users/sjr/Library/Developer/Xcode/iOS DeviceSupport/13.3.1
(17D50)/Symbols/usr" /System "/Users/sjr/Library/Developer/Xcode/iOS
DeviceSupport/13.3.1 (17D50)/Symbols/System"
"/private/var/containers/Bundle/Application/62B3E66E1
" "/Users/sjr/Projects/my_app/build/ios/iphoneos"
"/var/containers/Bundle/Application/62B3E66E1"
"/Users/sjr/Projects/my_app/build/ios/iphoneos" /Developer
"/Users/sjr/Library/Developer/Xcode/iOS DeviceSupport/13.3.1
(17D50)/Symbols/Developer"
[  +35 ms] (lldb)     command script import
"/tmp/1D186BA70/fruitstrap_4c604fe43a334525340e269626a.py"
[   +4 ms] (lldb)     command script add -f
fruitstrap_4c604fe43a334525340e269626a.connect_command connect
[        ] (lldb)     command script add -s asynchronous -f
fruitstrap_4c604fe43a334525340e269626a.run_command run
[        ] (lldb)     command script add -s asynchronous -f
fruitstrap_4c604fe43a334525340e269626a.autoexit_command autoexit
[        ] (lldb)     command script add -s asynchronous -f
fruitstrap_4c604fe43a334525340e269626a.safequit_command safequit
[        ] (lldb)     connect
[  +52 ms] (lldb)     run
[ +277 ms] success
[        ] (lldb)     safequit
[ +120 ms] Process 434 detached
[  +48 ms] Application launched on the device. Waiting for observatory port.
[   +4 ms] Checking for advertised Dart observatories...
[+5026 ms] mDNS lookup failed, attempting fallback to reading device log.
[        ] Waiting for observatory port.

这个问题在Xcode中看起来有所不同(尽管很可能是完全相同的问题)。看起来可能是内存泄漏?我不确定如何阅读此信息。我出现一个看起来像这样的错误:

io.flutter.204.ui (625): signal SIGABRT

然后在下面的日志中:

Runner(439,0x1009c5800) malloc: enabling scribbling to detect mods to free blocks

Runner(439,0x1009c5800) malloc: recording malloc and VM allocation stacks using lite mode

2020-03-31 07:54:22.330547+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

2020-03-31 07:54:22.475589+0800 Runner[439:345566] Metal API Validation Enabled

2020-03-31 07:54:22.864937+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

2020-03-31 07:54:22.932713+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

2020-03-31 07:54:22.976036+0800 Runner[439:345823] flutter: Observatory listening on http://127.0.0.1:51027/Wl9caPukKFs=/

2020-03-31 07:54:22.993612+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

2020-03-31 07:54:23.030173+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

从字面上看,还有数百个确切的部分:

2020-03-31 07:54:23.030173+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

然后继续:

../../third_party/dart/runtime/vm/clustered_snapshot.cc: 68: error: Out of memory.

2020-03-31 07:54:35.497087+0800 Runner[439:346457] version=2.5.0 (Fri Sep 6 20:10:36 2019 +0200) on "ios_arm64"

thread=1245963, isolate=main(0x2cb9de000)

2020-03-31 07:54:35.510204+0800 Runner[439:346457]   pc 0x00000001013019ac fp 0x00000002d76837e0 Dart_DumpNativeStackTrace

2020-03-31 07:54:35.510996+0800 Runner[439:346457]   pc 0x0000000100e94518 fp 0x00000002d7683800 dart::Assert::Fail(char const*, ...)

2020-03-31 07:54:35.511862+0800 Runner[439:346457]   pc 0x0000000100f2969c fp 0x00000002d7683860 dart::FunctionDeserializationCluster::ReadFill(dart::Deserializer*)

2020-03-31 07:54:35.512319+0800 Runner[439:346457]   pc 0x0000000100f2e4ec fp 0x00000002d76839b0 dart::FullSnapshotReader::ReadIsolateSnapshot()

2020-03-31 07:54:35.512738+0800 Runner[439:346457]   pc 0x0000000100f34d88 fp 0x00000002d7683f70 dart::Dart::InitializeIsolate(unsigned char const*, unsigned char const*, unsigned char const*, unsigned char const*, unsigned char const*, long, void*)

2020-03-31 07:54:35.513417+0800 Runner[439:346457]   pc 0x00000001012e8220 fp 0x00000002d7684010 dart::CreateIsolate(dart::IsolateGroup*, char const*, void*, char**)

2020-03-31 07:54:35.514492+0800 Runner[439:346457]   pc 0x0000000100b0ccd4 fp 0x00000002d7684270 flutter::DartIsolate::CreateDartVMAndEmbedderObjectPair(char const*, char const*, char const*, char const*, Dart_IsolateFlags*, std::__1::shared_ptr<flutter::DartIsolate>*, bool, char**)

2020-03-31 07:54:35.515065+0800 Runner[439:346457]   pc 0x0000000100b0c4fc fp 0x00000002d7684450 flutter::DartIsolate::CreateRootIsolate(flutter::Settings const&, fml::RefPtr<flutter::DartSnapshot const>, fml::RefPtr<flutter::DartSnapshot const>, flutter::TaskRunners, std::__1::unique_ptr<flutter::Window, std::__1::default_delete<flutter::Window> >, fml::WeakPtr<flutter::IOManager>, fml::WeakPtr<flutter::ImageDecoder>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Dart_IsolateFlags*, std::__1::function<void ()>, std::__1::function<void ()>)

2020-03-31 07:54:35.515707+0800 Runner[439:346457]   pc 0x0000000100b15000 fp 0x00000002d7684720 flutter::RuntimeController::RuntimeController(flutter::RuntimeDelegate&, flutter::DartVM*, fml::RefPtr<flutter::DartSnapshot const>, fml::RefPtr<flutter::DartSnapshot const>, flutter::TaskRunners, fml::WeakPtr<flutter::IOManager>, fml::WeakPtr<flutter::ImageDecoder>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::function<void (long long)>, flutter::RuntimeController::WindowData, std::__1::function<void ()>, std::__1::function<void ()>)

2020-03-31 07:54:35.516437+0800 Runner[439:346457]   pc 0x0000000100b1b858 fp 0x00000002d7684b50 flutter::Engine::Engine(flutter::Engine::Delegate&, flutter::DartVM&, fml::RefPtr<flutter::DartSnapshot const>, fml::RefPtr<flutter::DartSnapshot const>, flutter::TaskRunners, flutter::Settings, std::__1::unique_ptr<flutter::Animator, std::__1::default_delete<flutter::Animator> >, fml::WeakPtr<flutter::IOManager>)

2020-03-31 07:54:35.517172+0800 Runner[439:346457]   pc 0x0000000100b2c1d0 fp 0x00000002d7684fe0 std::__1::__function::__func<fml::internal::CopyableLambda<flutter::Shell::CreateShellOnPlatformThread(flutter::DartVMRef, flutter::TaskRunners, flutter::Settings, fml::RefPtr<flutter::DartSnapshot const>, fml::RefPtr<flutter::DartSnapshot const>, std::__1::function<std::__1::unique_ptr<flutter::PlatformView, std::__1::default_delete<flutter::PlatformView> > (flutter::Shell&)>, std::__1::function<std::__1::unique_ptr<flutter::Rasterizer, std::__1::default_delete<flutter::Rasterizer> > (flutter::Shell&)>)::$_0>, std::__1::allocator<fml::internal::CopyableLambda<flutter::Shell::CreateShellOnPlatformThread(flutter::DartVMRef, flutter::TaskRunners, flutter::Settings, fml::RefPtr<flutter::DartSnapshot const>, fml::RefPtr<flutter::DartSnapshot const>, std::__1::function<std::__1::unique_ptr<flutter::PlatformView, std::__1::default_delete<flutter::PlatformView> > (flutter::Shell&)>, std::__1::function<std::__1::unique_ptr<flutter::Rasterizer, std::__1::default_delete<flutter::Rasterizer> > (flutter::Shell&)>)::$_0> >, void ()>::operator()()

2020-03-31 07:54:35.518362+0800 Runner[439:346457]   pc 0x0000000100add9e8 fp 0x00000002d7685030 fml::MessageLoopImpl::FlushTasks(fml::FlushType)

2020-03-31 07:54:35.518837+0800 Runner[439:346457]   pc 0x0000000100ae209c fp 0x00000002d7685050 fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*)

2020-03-31 07:54:35.519148+0800 Runner[439:346457]   pc 0x000000019eb6503c fp 0x00000002d7685060 <redacted>

2020-03-31 07:54:35.519351+0800 Runner[439:346457]   pc 0x000000019eb64d78 fp 0x00000002d7686110 <redacted>

2020-03-31 07:54:35.519583+0800 Runner[439:346457]   pc 0x000000019eb64448 fp 0x00000002d76861a0 <redacted>

所以对于我未经训练的眼睛,它似乎正在尝试这样做:

2020-03-31 07:54:23.030173+0800 Runner[439:345566] Failed to find snapshot: /private/var/containers/Bundle/Application/E00E6D3690/Runner.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin

数千次,直到它用尽内存,但是我不太确定这是什么,或者如何开始尝试解决它。​​

编辑:Flutter Doctor输出。

flutter doctor -v

[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.15.4 19E264b,

    locale en-AU)

    • Flutter version 1.9.1+hotfix.6 at /Users/sjr/flutter

    • Framework revision 68587a0916 (7 months ago), 2019-09-13 19:46:58 -0700

    • Engine revision b863200c37

    • Dart version 2.5.0



[✗] Android toolchain - develop for Android devices

    ✗ Unable to locate Android SDK.

      Install Android Studio from:

      https://developer.android.com/studio/index.html

      On first launch it will assist you in installing the Android SDK

      components.

      (or visit https://flutter.dev/setup/#android-setup for detailed

      instructions).

      If the Android SDK has been installed to a custom location, set

      ANDROID_HOME to that location.

      You may also want to add it to your PATH environment variable.







[✓] Xcode - develop for iOS and macOS (Xcode 11.4)

    • Xcode at /Applications/Xcode.app/Contents/Developer

    • Xcode 11.4, Build version 11E146

    • CocoaPods version 1.7.5



[!] Android Studio (not installed)

    • Android Studio not found; download from

      https://developer.android.com/studio/index.html

      (or visit https://flutter.dev/setup/#android-setup for detailed

      instructions).



[!] Connected device

    ! No devices available



! Doctor found issues in 3 categories.

编辑:

@Hannes Sverrisson的建议导致的错误代码:

Running pod install...                                              4.7s
Running Xcode build...                                                                                                 

Xcode build done.                                           16.8s
Failed to build iOS app

Error output from Xcode build:
    ** BUILD FAILED **

Xcode's output:

 === BUILD TARGET PromisesObjC OF PROJECT Pods WITH CONFIGURATION Release ===

    In file included from

    /Users/sjr/Projects/my_app/ios/Pods/GoogleDataTransport/GoogleDataTran

    sport/GDTCORLibrary/GDTCORLifecycle.m:22:

    In file included from

    /Users/sjr/Projects/my_app/ios/Pods/GoogleDataTransport/GoogleDataTran

    sport/GDTCORLibrary/Private/GDTCORRegistrar_Private.h:17:

    In file included from

    /Users/sjr/Projects/my_app/build/ios/Release-iphoneos/GoogleDataTransp

    ort/GoogleDataTransport.framework/Headers/GDTCORRegistrar.h:19:

    In file included from

    /Users/sjr/Projects/my_app/build/ios/Release-iphoneos/GoogleDataTransp

    ort/GoogleDataTransport.framework/Headers/GDTCORPrioritizer.h:19:

    /Users/sjr/Projects/my_app/build/ios/Release-iphoneos/GoogleDataTransp

    ort/GoogleDataTransport.framework/Headers/GDTCORLifecycle.h:26:11: error:

    duplicate protocol definition of 'GDTCORLifecycleProtocol' is ignored

    [-Werror,-Wduplicate-protocol]

    @protocol GDTCORLifecycleProtocol <NSObject>

然后还有成千上万个“文件内”错误,直到失败。

编辑:git push之后,重新创建并提取:构建过程中Xcode中显示的错误。

enter image description here

4 个答案:

答案 0 :(得分:6)

1)更新mac和Xcode。

2)打开Xcode并安装模拟器。

3)从Flutter应用程序目录中,在Xcode中打开ios / Runner.xcworkspace,然后在“签名和功能”下选择一个开发团队。

4)按照https://flutter.dev/docs/development/ios-project-migration

的说明进行操作

5)然后运行:

flutter clean
flutter build ios
flutter run

全部在您的项目文件夹中。

6a)如果上述方法不起作用,而您正在使用git或其他外部源代码管理,则我将所有内容提交并向上推送。然后,我删除了该文件夹,git再次获取了该文件夹,一切正常。

6b)另一个解决方案是删除所有吊舱:

Remove the Pods folder and Podfile.lock files.

,然后重建吊舱:

cd ios
pod deintegrate
cd ..
flutter clean
flutter build ios

答案 1 :(得分:1)

我有一个类似的问题。我下载了Flutter示例,经过短暂的白屏显示后,它一直崩溃,没有任何可理解的错误。我终于发现,某些代码或软件包依赖于Flutter较稳定版本更高的版本。

在终端中输入:

flutter channel

查看您当前的频道是什么,然后您可以尝试主频道或Beta频道:

flutter channel master
flutter upgrade

看看是否有帮助!

也请检查以下建议的解决方案:https://github.com/flutter/flutter/issues/29286

您需要运行

flutter build ios --debug (or --profile or --release) 
flutter run --release

在Xcode中启动项目之前。

答案 2 :(得分:0)

目前似乎没有足够的信息可以帮助我们解决您的问题,但是对于Flutter医生来说,您使用的Flutter SDK版本可能有问题,因为它已经存在7个月了,并且您正在使用新版本xcode构建项目。似乎存在与该版本SDK相关的问题。 Reference

因此,首先尝试使用flutter upgrade

更新flutter sdk

请在更新后更新Flutter Doctor和最新调试运行的输出,以便我们尝试进一步帮助您。

此外,您是否可以尝试在模拟的iOS设备以及外部设备上运行它,以查看是否将xcode项目配置为构建问题?

答案 3 :(得分:-2)

我也遇到了这个错误,但是在安装了最新版本的android studio之后,该错误已经消失了。我认为这是系统而非手动发生的。您也应该尝试一下。