6
6

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 5 years have passed since last update.

UnityのiOSビルドで出力されるXcodeプロジェクトの設定自動化。ファイル毎のARC無効設定を追加する

Last updated at Posted at 2017-02-13

Xcodeプロジェクトの設定変更を自動化(コンパイルフラグの追加)

UnityのXcodeプロジェクト出力時、あるファイルのARC無効設定を追加する必要が出てきたのでメモ。
基本的にはEnable BitcodeをNoにするやり方と同じ。

PBXProjectを使ってプロジェクト設定を書き換えることで、コンパイルフラグの追加も自動化できる。

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif

public static class MyBuildPostprocess
{
	[PostProcessBuild(999)]
	public static void OnPostProcessBuild( BuildTarget buildTarget, string path)
	{
		if(buildTarget == BuildTarget.iOS) {
			string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

			PBXProject pbxProject = new PBXProject();
			pbxProject.ReadFromFile(projectPath);

			string target = pbxProject.TargetGuidByName("Unity-iPhone");
			string fileGuid = pbxProject.FindFileGuidByProjectPath("Libraries/Plugins/iOS/NativeDialogManager.mm");
			List<string> flags = new List<string>() {"-fno-objc-arc"};
			pbxProject.SetCompileFlagsForFile(target, fileGuid, flags);

			pbxProject.WriteToFile (projectPath);
		}
	}
}

調べてみるとフレームワークの追加やInfo.plistの追加もできる模様。積極的に活用していきたい。

参考

Unity - Scripting API: PBXProject

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?