com.apple.dt.deviceprocesscontrolservice Code=8 Error when running WidgetBundle Targets

When I try to run CharacterDetail target from the example code of EmojiRangers - Game Status Final from Widgets Code-Along of WWDC20, encountered the following error.

I have been trying to replicate a similar behavior of creating a WidgetBundle in my own SwiftUI 2 app, but faced a similar issues.

I am not an expert in Swift or SwiftUI, but I'm a public beta user nonetheless and have created a handful of apps using the SwiftUI.

My understanding of this problem is, when creating bundle and assigning @main, as per the error messages, Xcode gets confused on which widget to show on the Simulator.

i.e., EmojiRangers app contains EmojiRangerBundle inside LeaderboardWidget.swift. This bundle contains calls to two different widgets:
  1. EmojiRangerWidget()

  2. LeaderboardWidget()

I speculate that Xcode is not able to understand which Widget to preview when run on the Simulator.

I hope @apple figures out the solution.


Following is the error message:
Code Block
SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.example.apple-samplecode.Emoji-Rangers.Intermediate' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=2 "Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'" UserInfo={NSLocalizedDescription=Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.example.apple-samplecode.Emoji-Rangers.Intermediate' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=2 "Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'" UserInfo={NSLocalizedDescription=Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'}., NSUnderlyingError=0x7fda3f064360 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=2 "Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'" UserInfo={NSLocalizedDescription=Please specify the widget kind in the scheme's Environment Variables using the key '_XCWidgetKind' to be one of: 'EmojiRangerWidget', 'LeaderboardWidget'}}}

I ran into the same issue when tried to debug a 2nd widget in our app. To fix the issue go to Edit Scheme, select Run on the left panel, and then at the top select the Arguments tab. Assign a string value of the widget you want to test as the value of _XCWidgetKind and check the box on the left hand side. Now you can build and test your widget.
@Cabearsfan seems to be correct, but the thing is if you are trying to test multiple widgets, this when you gonna start pull your hair, so I found this article by apple they mention Cabearsfan solution, but what I have tried that they didn't really mention how, I duplicated all of the three environment variables, and assigned in the _XCWidgetkind the string that is located in Widget struct for the variable kind, and the rest changed to the size of the preview you gonna run or what you have for the family. so if you have 3 widgets you might need to have like 3 duplicates of those environment assigning the detail per each. I am not sure if that will always work but for me that was the only way that I got rid of the error for now.

In my case it was due to empty widget's families list:

...
.supportedFamilies(families)
...

var families: [WidgetFamily] {
        if #available(iOSApplicationExtension 16.0, watchOS 9.0, *) {
            return [.accessoryCircular, .accessoryInline, .systemSmall]
        } else {
            return [] // <------------------------- problem
        }
    }

I've changed that to non-empty for <16.0 case:

var families: [WidgetFamily] {
        if #available(iOSApplicationExtension 16.0, watchOS 9.0, *) {
            return [.accessoryCircular, .accessoryInline, .systemSmall]
        } else {
            return [.systemSmall]
        }
    }

@seriyvolk83 you helped me much, that's correct.

com.apple.dt.deviceprocesscontrolservice Code=8 Error when running WidgetBundle Targets
 
 
Q