Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by amitedgy · Oct 09, 2017 at 11:34 AM · post processingautomation

automated post process frameworks

Trying to automate using post process from unity to xcode. Looked through and tried all relavent parts of PBXProject library including: PBXProject.AddFrameworkToProject PBXProject.AddFileToBuild and others but still the the frameworks are not add like when dragged manually PBXProject.AddFileToEmbedFrameworks - did manage to the frameworks to the embedded binaries but not in to linked frameworks. The build is successful when done manually.

Also having problems automatically adding a second run script in build phases. Thanks for the help

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by peter_pimley_unity · Oct 29, 2017 at 09:38 PM

Hi,

Is there a specific bit of code you're having trouble with, that you can post here?

Some things to keep in mind when using the PBXProject API are:

Use the [PostProcessBuild] attribute, and use the correct function signature.

See https://docs.unity3d.com/ScriptReference/Callbacks.PostProcessBuildAttribute.html

Unity will run a [PostProcessBuild] function after doing the build. Your function must return void and take two parameters, a BuildTarget target and a string pathToBuiltProject. The BuildTarget tells you which platform the build was for, and the string tells you where the build was saved. So for example if you were only interested in processing an iOS build, you could return from the function if the BuildTarget was anything other than BuildTarget.iOS:

 [PostProcessBuild]
 private static void PostprocessBuild(BuildTarget target, string pathToBuiltProject)
 {
     if (target != BuildTarget.iOS)
         return;

The string is the location of the build. For iOS, this is the location of the folder that contains the Unity-iPhone.xcodeproj file. So in order to access the project.pbxproj file you need to do something like this:

 string pbxFilename = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"

Load the file into your PBXProject instance

After instantiating a new PBXProject, you need to load the data from the file on disk into your instance. Use PBXProject.ReadFromFile, ReadFromString or ReadFromStream.

 PBXProject proj = new PBXProject();
 proj.ReadFromFile (pbxFilename);

Add your framework

This is the easy part, just call PBXProject.AddFrameworkToProject. For the first parameter, pass in the result of PBXProject.TargetGuidByName, passing in the string returned by PBXProject.GetUnityTargetName. The second parameter is the name of the framework, and the third specifies whether it is optional (i.e. false means required).

For example, to add ARKit.framework to your project, do this:

 string targetName = PBXProject.GetUnityTargetName ();
 string guid = proj.TargetGuidByName (targetName);

 proj.AddFrameworkToProject(guid, "ARKit.framework", false);

Write the project back to disk

This is an easy step to forget. Use one of PBXProject.WriteToFile, WriteToStream or WriteToString to serialize the PBXProject instance back out to disk:

 proj.WriteToFile (pbxFilename);

Putting it all together

Putting all the previous steps together, here is a minimal C# script that does the following:

  • Early-exits of the build is not for iOS

  • Creates a PBXProject instance, and loads the data in from the project.pbxproj file.

  • Adds ARKit.framework.

  • Saves back out to the project.pbxproj file.

     public class MyBuildScript {
         
         [PostProcessBuild]
         private static void PostprocessBuild(BuildTarget target, string pathToBuiltProject)
         {
             Debug.LogFormat ("Postprocessing build at \"{0}\" for target {1}", pathToBuiltProject, target);
             if (target != BuildTarget.iOS)
                 return;
     
             PBXProject proj = new PBXProject();
             string pbxFilename = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
             proj.ReadFromFile (pbxFilename);
     
             string targetName = PBXProject.GetUnityTargetName ();
             string guid = proj.TargetGuidByName (targetName);
             proj.AddFrameworkToProject(guid, "ARKit.framework", false);
     
             proj.WriteToFile (pbxFilename);
         }
     }
    
    
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image moltow · Jan 12, 2018 at 02:47 PM 1
Share

I think this answer should be marked as correct. Thank you, @peter_pimley_unity for this. It is very helpful.

I'm going to add a couple of other notes as it took me quite a bit of time and searching to piece together all of the information needed to accomplish automating the adding of a framework to Xcode (this answer was the most helpful resource I found, btw)...

First: in order to use this, you need to have your script in a folder called "Editor" or its subfolder. Second: you need to include the correct namespaces. Some of these are apparent using Unity's API documentation, but others aren't. Here's the complete list...

using UnityEngine; // only needed for the Debug logging. using UnityEditor; // needed to gain access to the BuildTarget enum. using UnityEditor.Callbacks; // needed to gain access to the PostProcessBuild class. using UnityEditor.iOS.Xcode; // needed to gain access to the PBXProject class.

avatar image keil_unity · Jan 25 at 10:46 PM 0
Share

This is awesome! I did this though and although i see arkit in my xcode file when I build i receive linker errors for _UnityARKit any ideas?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

URP Post-Processing single button 0 Answers

BuildFailedException: Incremental Player build failed! 2 Answers

Force package import with script errors 0 Answers

Automating transition animations through script 0 Answers

In FastBloom(Bloom Optimized) shader, what's the difference between Standard and Sgx blur type? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges