App crashes at launch on missing symbol AVPlayerView... except on first launch

I don't know what triggered this in a previously-running application I'm developing: When I have the build target set to "My Mac (designed for iPad)," I now must delete all the app's build materials under DerivedData to get the app to build and run exactly once. Cleaning isn't enough; I have to delete everything.

On second launch, it will crash without even getting to the instantiation of the application class. None of my code executes.

Also: If I then set my iPhone as the build target, the app will build and run repeatedly. If I then return to "My Mac (designed for iPad)," the app will again launch once and then crash on every subsequent launch.

The crash is the same every time:

dyld[3875]: Symbol not found: _OBJC_CLASS_$_AVPlayerView
  Referenced from: <D566512D-CAB4-3EA6-9B87-DBD15C6E71B3> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Debugger/libViewDebuggerSupport.dylib
  Expected in:     <4C34313C-03AD-32EB-8722-8A77C64AB959> /System/iOSSupport/System/Library/Frameworks/AVKit.framework/Versions/A/AVKit

Interestingly, I haven't found any similar online reports that mention this symbol.

Has anyone seen this behavior before, where the crash only happens after the first run... and gets reset when you toggle the target type?

Hi @Stokestack , really strange behaviour.

AVPlayerView is really an old view present on AVkit on Mac OS 10.9, and it is used on QuickTime App itself. https://developer.apple.com/documentation/avkit/avplayerview

If you can generate some sort of sample project and tell which is your enviromment, probably could help. Error simply tell that no AVPlayerView is found on Mac OS, that is really strange

Bye Rob

Hello @Stokestack, thank you for your post. I suspect the issue is due to the fact that AVPlayerView is only available on macOS. On iOS and iPadOS, you would use AVPlayerViewController instead. In addition, VideoPlayer is a SwiftUI View that is available on both macOS and iOS/iPadOS, so might be a more suitable option.

As @GRALInfo mentioned, if you are able to share a test project, that'd be great. You can find tips on creating and sharing a test project in Creating a Test Project.

Hi @Engineer @Stokestack , as @Engineer mentioned, it could be a issue on iOS side. If this is the use case, @Stokestack , you should wrap piece of code using AVPlayerView with this conditional compilation :

// Swift  
#if targetEnvironment(macCatalyst)
    // Code specific to Mac.
#else
    // Code to exclude from Mac.
#endif
// Objective C
#if TARGET_OS_MACCATALYST
    // Code specific to Mac.
#else
    // Code to exclude from Mac.
#endif

Bye Rob

Thanks guys. But I'm not using AVPlayerView! That string doesn't even occur in my source, or in DerivedData.

I can't post my entire project. I'll see if I can reproduce it with a basic test one.

App crashes at launch on missing symbol AVPlayerView... except on first launch
 
 
Q