-
-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to add an Embed App Clip phase #753
Comments
I think the missing bit is adding the file reference and build file objects to the project. project.add(object: fileReference)
project.add(object: buildFile) XcodeGen and Tuist can be useful references as they both leverage XcodeProj. Hope this helps |
Thanks for this - those are helpful references. I am still having an issue however. The problem seems to be with the PBXFileReference. And it's not clear from those code excerpts how this should be created. Without adding the file reference I can create an empty buildphase, but as soon as I try to add the fileReference to the buildphase I get a corrupted Xcode project with the error message: I am creating the file reference and adding it to the project. I have also tried adding it to the mainGroup.children array as without this step it gets an identifier prefixed with 'TEMP'. However both with and without that step, I am getting the corrupted project issue. Current iteration of code below - any thoughts much appreciated!
|
I've tried out the snippet in a sample and hit the same error, looks like there's a small type error in the build file attributes, where it should be an array of string flags rather than a single string/ let buildFile = PBXBuildFile(file: fileReference, settings: ["ATTRIBUTES": ["RemoveHeadersOnCopy"]]) Note, if you are modifying a project that already has both targets within it, existing file references can be used rather than creating new ones: func addAppClipEmbedPhase(pbxProj: PBXProj, appTarget: PBXTarget, appClipTarget: PBXTarget) throws {
guard !appTarget.buildPhases.contains(where: { $0.name() == "Embed App Clip" }) else {
throw ProjectEditError.error("Target already has a build phase called Embed App Clip")
}
let embedAppClipsBuildPhase = PBXCopyFilesBuildPhase(
dstPath: "$(CONTENTS_FOLDER_PATH)/AppClips",
dstSubfolderSpec: .productsDirectory,
name: "Embed App Clip"
)
pbxProj.add(object: embedAppClipsBuildPhase)
appTarget.buildPhases.append(embedAppClipsBuildPhase)
guard let appClipFileReference = appClipTarget.product else {
throw ProjectEditError.error("AppClip file reference is not available")
}
let buildFile = PBXBuildFile(file: appClipFileReference, settings: ["ATTRIBUTES": ["RemoveHeadersOnCopy"]])
pbxProj.add(object: buildFile)
embedAppClipsBuildPhase.files = [buildFile]
} |
Thank you so much! Just tried that and its working perfectly now |
I'm trying to write a script to embed an AppClip into a project.
There are 2 steps.. Adding the AppClip as a dependency of the main app target, and adding a Copy Files build phase that embeds the AppClip.
Step 1 appears to be working ok, but step 2 - The Copy Files phase is created but doesn't have any content.
This is what I have so far:
I suspect I may be missing a step and the buildFile needs to be added somewhere else? But not sure where? Thanks!
The text was updated successfully, but these errors were encountered: