Mac Xcode projects are missing a build target and cannot be built (found in Unity 2021.2.11)

I’ve just submitted a bug report for this.

1. What happened
I’ve discovered that mac xcode projects being compiled out of Unity are missing a build target and can not be built in Xcode.

2. How can we reproduce it using the example you attached
It’s very simple to reproduce:

  • start a new project in 2021.2.11, I selected the 3D template, and named the project BugReport
  • make sure the build platform is mac standalone, tick Create Xcode Project in build settings, add the SampleScene to the list of scenes to build
  • Build out an xcode project
  • Open the Xcode project, notice that the Build button in xcode is greyed out
  • If you then click on the BugReport target in the header of the application, then choose Edit Scheme, the build target for the Build scheme shows “TEST (missing)”, there’s no build target added to the schemes so the project can not be built.

note: it doesn’t matter if you have Mono or IL2CPP as the scripting backend, the result is the same.

reported bug case number is 1404100

Does the xcode project at least have the hardened runtime setup in 2021?
Because 2019 LTS builds an xcode project which needs you to manually setup the ‘hardened-runtime’ every time, which is bad… You can not even keep xcode settings between builds

This is a bit of a deviation from the original topic I posted, but I’ve got a decent answer to help you with this. It should be expected that Unity have not enabled the hardened runtime by default, it’s not needed for builds that are submitted to Apple’s AppStore ie. it wouldn’t be appropriate for all mac developers to have this on by default:

However, you aren’t required to notarize software that you distribute through the Mac App Store because the App Store submission process already includes equivalent security checks.
https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution?language=objc

It’s only for third party distribution that you need to turn it on and you can do this using build post processing. The only thing Unity could do perhaps is to add a tickbox to the project settings to set this for us in compiled xcode projects:

[PostProcessBuildAttribute( 1 )]
public stiatc void OnPostprocessBuild ( BuildTarget buildTarget, string pathToBuiltProject ) {
        var xCodeProjFolderPath = $"{pathToBuiltProject}/{PlayerSettings.productName}.xcodeproj";
        var projPath = $"{xCodeProjFolderPath}/project.pbxproj";
        var project = new PBXProject();
        project.ReadFromString( File.ReadAllText( projPath ) );
        var targGUID = project.TargetGuidByName( PlayerSettings.productName );
        project.SetBuildProperty( targGUID, "ENABLE_HARDENED_RUNTIME", "YES" );
        File.WriteAllText( projPath, project.WriteToString() );
}

note: the paths to the xcode project and build targets differ between major unity versions, they have made changes to them in major versions over the last couple of years, so if you’re using Unity 2019 you might need to check the paths, these ^ should be correct as of Unity 2021.2

1 Like

Regarding the original topic I posted about, I’ve received a response from Unity that the issue is being tracked and they’re aware of the issue. I don’t have any estimates from them on when this might be fixed.

we have the fix in the works (as in - it is fixed and waits to be merged into the next release), so just wait a bit 8)

1 Like

No worries, thanks.

Bump…any update on this unfortunate scenario?
I am using 2021.2.7f1 and it still seems to be unable to build.

well the original post says

so yes, 2021.2.7 has this bug for sure ;-). Try updating to the latest 2021.2 (or even .3)

Yup 2021.3 seems to have fixed it.