Xcode 14 watchOS Error

Entry Point (_main) undefined for architecture x86_64, Anyone else getting this after updating settings request by xcode 14 and your watch app?

Post not yet marked as solved Up vote post of lmDeveloper1 Down vote post of lmDeveloper1
3.2k views

Replies

There are three possible solutions to this issue after upgrading settings to convert an extension based watch app to a single target watch app.

If you're using SwiftUI, and you're using App, then you need to annotate your App type with @main. For example:

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationStack {
                ContentView()
            }
        }
    }
}

Otherwise, if you're using Swift, but not using App (for example if you're using storyboards or you are using a mix of storyboards and SwiftUI), then you need to annotate your WKApplicationDelegate type with @main. If you had an WKExtensionDelegate in your app prior to the upgrade, it should have been renamed to WKApplicationDelegate for you by the settings upgrade process (though in some cases this needs to be done manually). For example:

@main
class AppDelegate: NSObject, WKApplicationDelegate {
    ...
}

Lastly, if you're using Objective-C, then you need to add a main function which calls WKApplicationMain and passes in your delegate class type (which must conform to WKApplicationDelegate). For example:

#import <WatchKit/WatchKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    NSString * appDelegateClassName;
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
    }

    return WKApplicationMain(argc, argv, appDelegateClassName);
}

The settings upgrade process will try to perform these steps automatically, but can't handle all possible project structures. Please file a report via Feedback Assistant and attach your original Xcode project if possible, so that we can investigate why this project wasn't able to be fully converted automatically.

  • this got it to build for me !, however now im having an issue where it states when trying to run the iOS app on the iOS16 simulator:

    Please try again later. Found WatchKit 2.0 app at /Users/xxxxxxx/Library/Developer/CoreSimulator/Devices/E18868EE-130C-4159-AAF2-95319072DD5E/data/Library/Caches/com.apple.mobile.installd.staging/temp.JH6Xuf/extracted/Payload/TestingApp.app/Watch/TesterExt.app but it does not have a WKWatchKitApp or WKApplication key set to true in its Info.plist

  • I am trying to build a watchOS app through CMake (generator used is xcode) and Objective-C. When I added the above(int main as entry point), I get an error saying 'WKApplicationMain' is not found. Am using WatchOS 8.3 sdk. Can you help ?

Add a Comment

This worked to get it to build, i needed to hand add an extension delegate and the corresponding main / infoplist entries. but now when trying to run on a iphone simulator it says this. Feel as if im missing something else.

Please try again later. Found WatchKit 2.0 app at /Users/x/Library/xxxxxxDeveloper/CoreSimulator/Devices/E18868EE-130C-4159-AAF2-95319072DD5E/data/Library/Caches/com.apple.mobile.installd.staging/temp.JH6Xuf/extracted/Payload/TestingApp.app/Watch/TesterExt.app but it does not have a WKWatchKitApp or WKApplication key set to true in its Info.plist

  • i noticed if i create a new watch app in xcode 14, it will create the app but not add it to the build phases as a dependency and embed watch content. After the migrate those 2 are still there can they be removed now in xcode 14? I noticed if i remove both the ios app will run on the simulator. Just curious if those need to be removed

Add a Comment

I attached a sample project, clean xcode 13 ios app, added watch target, then opened up xcode 14 did the migration and doesnt run on ios simulator (seems to run on device though) so maybe its a simulator issue / check? FB10066285

I was getting the error after updating my project to consolidate watchOS app extension and app targets. Adding a WKApplication key to the watch app's Info.plist (type: boolean, value: 1) fixed this for me.

It points to a crash on @main on my AppDelegate class (WKApplicationDelegate). There isn't much in the debugger other than: Couldn't instantiate class _TtC30PDX_Transit_WatchKit_Extension23MainInterfaceController

Any ideas of where I can begin with this?

Xcode 14 Beta 3

  • @marioguzman: We're seeing the same error behavior now with our WKApplicationDelegate. It only started to occur when we combined the Watch targets to a single target as with Xcode 14 recommendation. Did you find a solution for this?

Add a Comment

We are seeing the same error message as @marioguzman. Info.plist contains WKApplication key entry set to YES in addition we have the Info.plist from the WatchExtension where the WKExtensionDelegateClassName is set with the value set to $(PRODUCT_MODULE_NAME).ExtensionDelegate.

The ExtensionDelegate looks as follows:

import SwiftUI

// ScenePhase observation doesn't work reliably
// https://developer.apple.com/forums/thread/650632
// Implement custom appDelegate and notiy about lifecycle changes
@main
class ExtensionDelegate: NSObject, WKApplicationDelegate {
    func applicationWillEnterForeground() {
        NotificationCenter.default.post(name: Notification.Name.willEnterForeground, object: nil, userInfo: nil)
    }

    func applicationDidEnterBackground() {
        NotificationCenter.default.post(name: Notification.Name.didEnterBackground, object: nil, userInfo: nil)
    }
}

And the watch app crashes at the @main with

Watch[71777:6577905] [default] -[SPRemoteInterface createViewController:className:properties:contextID:info:gestureDescriptions:clientIdentifier:interfaceControllerCreationCompletion:]:3230: Critical failure. Simulating crash: Condition failed:"NO". Couldn't instantiate class _TtC15Watch_Extension17HostingController