2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UnityのiOSビルド時にBuild SettingsやBuild Phases等の項目を自動追加する方法

Posted at

実装環境

  • Unity 2019.2.21f1
  • Xcode 11.6

参考サイト

方法

  1. 参考サイト記載のサンプルプログラムをダウンロードし、'Assets/Editor'フォルダ下に設置

  2. Users/UserOnPostBuild.cs内のEditProjメソッドを適宜書き換える

PostXcodeBuild.cs
    private static void EditProj(string pathToBuiltProject)
    {
            // 項目追加に必要な情報を取得(必須)
            var projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
            var pbxProj = new Users.Custom.PBXProject();
            pbxProj.ReadFromFile(projPath);
            var targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");

            // BuildPhasesの追加サンプル
            // 不要なら削除
            pbxProj.AppendShellScriptBuildPhase(targetGuid,"Run Script copy_test.sh","/bin/sh","./../Assets/Editor/copy_test.sh");

            // BuildSettingsの追加処理サンプル
            // 不要なら削除
            pbxProj.SetBuildProperty(targetGuid, "IPHONEOS_DEPLOYMENT_TARGET", "9.0");

            // Frameworkの追加処理サンプル
            // 不要なら削除
            pbxProj.AddFrameworkToProject(targetGuid, "CoreBluetooth.framework", true);

            // embedded frameworkの追加サンプル
            // 不要なら削除
            var defaultLocationInProj = "Frameworks/Plugins/iOS/EmbeddedFramework/";
            var relativeCoreFrameworkPath = "";
            string[] commonFrameworkNames=new string[]{"EmbeddedFramework1","EmbeddedFramework2"};
            foreach (var frameworkNameTemp in commonFrameworkNames) {
                var frameworkName = frameworkNameTemp+".framework";
                 relativeCoreFrameworkPath = Path.Combine(defaultLocationInProj, frameworkName);
                AddDynamicFrameworks (ref pbxProj,targetGuid,relativeCoreFrameworkPath);
            }

            // .dylibの追加サンプル
            // 不要なら削除
            pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libresolv.dylib", "Frameworks/libresolv.dylib", Users.Custom.PBXSourceTree.Sdk));

            // 追加処理を書き込む(必須)
            pbxProj.WriteToFile(projPath);
        }
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?