How do I access [Link Binary With Libraries] within Build Phases in Xcode with PBXProject?

Hello, I am a developer who is developing as Unity in Korea.

I’m not good at English, so I write with a translator.

I’m currently trying to automate IOS build.

How do I access [Link Binary With Libraries] within Build Phases in Xcode with PBXProject?

alt text

[Link Binary With Libraries] I want to approach and add the Libraries I want, but it’s not easy.

================================================================

string filename = APP_NAME;

string strOutputDir = Directory.GetCurrentDirectory() + “/” + TARGET_DIR; ;

string projectPath = path + “/Unity-iPhone.xcodeproj/project.pbxproj”;

PBXProject pbxProject = new PBXProject();

pbxProject.ReadFromFile(projectPath);

string str_Main_Guid = pbxProject.GetUnityMainTargetGuid();

string str_Framework_Guid = pbxProject.GetUnityFrameworkTargetGuid();

================================================================

I made it like this. I don’t know anymore.

If anyone knows, please teach me.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

안녕하세요. 저는 한국에서 유니티로 개발중인 개발자입니다.

영어를 잘 하지 못하여서 번역기로 글을 남겨요.

현재 IOS 빌드 자동화를 해볼려고 만드는 중인데.

PBXProject로 Xcode 에서 Build Phases 안에 [Link Binary With Libraries] 에 접근을 어떻게 하나요.

[Link Binary With Libraries] 접근을 하여서 제가 원하는 Librarie를 추가하고 싶은데 쉽지가 않네요.

================================================================

string filename = APP_NAME;

string strOutputDir = Directory.GetCurrentDirectory() + “/” + TARGET_DIR; ;

string projectPath = path + “/Unity-iPhone.xcodeproj/project.pbxproj”;

PBXProject pbxProject = new PBXProject();

pbxProject.ReadFromFile(projectPath);

string str_Main_Guid = pbxProject.GetUnityMainTargetGuid();

string str_Framework_Guid = pbxProject.GetUnityFrameworkTargetGuid();

================================================================

이렇게 만들었는데. 더 이상 잘 모르겠습니다.

혹시 아시는분 있으시면 저에게 가르침을 주세요.

Hello! We had a similar issue and found out a way to link our binaries. First, you need to get the corrent phase guids, which is “Link Binaries With Libraries”;

var unityLinkPhaseGuid = pbxProject.GetFrameworksBuildPhaseByTarget(str_Main_Guid);
var unityFrameworkLinkPhaseGuid = pbxProject.GetFrameworksBuildPhaseByTarget(str_Framework_Guid);

Then you need to add your frameworks to these phases;

    // targetFrameworkGuid is guid of the binary you want to link with libraries.
    // If you provide the framework, you should use pbxProject.AddFile() 
    // and use the returned guid
    
    pbxProject.AddFileToBuildSection(str_Main_Guid, unityLinkPhaseGuid, targetFrameworkGuid);
    pbxProject.AddFileToBuildSection(str_Framework_Guid, unityFrameworkLinkPhaseGuid, targetFrameworkGuid);

After doing these and write all to pbxProject, your linking phase should be correct. You might still need to embed your frameworks. Use pbxProject.AddFileToEmbedFrameworks() to embed your frameworks.

This is also possible:

pbxProject.AddFrameworkToProject(targetGUID, “AppTrackingTransparency.framework”, true);

“true” will add the framework in the “Link Binary With Libraries” section with status “Optional”, “false” will be “Required”.