Last active
March 7, 2018 02:38
-
-
Save masayuki5160/91999522b950747f4a0c to your computer and use it in GitHub Desktop.
UnityでAndroid,iOSビルドを自動化するために試行錯誤
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
public class BuildBatch : MonoBehaviour { | |
// build iOS app | |
[UnityEditor.MenuItem("Tools/Build Project AllScene iOS")] | |
private static void BuildiOS(){ | |
Debug.Log("##########iOS Build Start#########"); | |
// 全てのシーンを取得する | |
EditorUserBuildSettings.SwitchActiveBuildTarget( BuildTarget.iOS ); | |
string[] allScene = new string[EditorBuildSettings.scenes.Length]; | |
int i = 0; | |
foreach( EditorBuildSettingsScene scene in EditorBuildSettings.scenes ){ | |
Debug.Log ("scenePath(" + i + ")" + scene.path); | |
allScene[i] = scene.path; | |
i++; | |
} | |
// オプションの設定 | |
BuildOptions opt = BuildOptions.Il2CPP; | |
// Rendering | |
PlayerSettings.renderingPath = RenderingPath.Forward; | |
PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.iOS, false); | |
PlayerSettings.gpuSkinning = true; | |
PlayerSettings.iOS.sdkVersion = iOSSdkVersion.DeviceSDK; | |
PlayerSettings.iOS.targetOSVersion = iOSTargetOSVersion.iOS_7_0; | |
PlayerSettings.bundleIdentifier = "jp.co.masayuki.tanaka"; | |
PlayerSettings.bundleVersion = "01.00.00"; | |
PlayerSettings.SetPropertyInt("ScriptingBackend", 1, BuildTargetGroup.iOS); | |
PlayerSettings.statusBarHidden = true; | |
string errorMsg_Device = BuildPipeline.BuildPlayer( | |
allScene, | |
"iOSDevice", | |
BuildTarget.iOS, | |
opt | |
); | |
if (string.IsNullOrEmpty(errorMsg_Device)){ | |
Debug.Log ("##########Success iOS Device Build#########"); | |
} else { | |
Debug.Log ("##########Failed iOS Device Build#########"); | |
Debug.Log (errorMsg_Device); | |
} | |
// シュミレーター用 | |
/* | |
PlayerSettings.iOS.sdkVersion = iOSSdkVersion.SimulatorSDK; | |
string errorMsg_Simulator = BuildPipeline.BuildPlayer( | |
allScene, | |
"Simulator", | |
BuildTarget.iOS, | |
opt | |
); | |
if (string.IsNullOrEmpty(errorMsg_Simulator)){ | |
Debug.Log ("##########Success Simulator Build#########"); | |
} else { | |
Debug.Log ("##########Failed Simulator Build#########"); | |
Debug.Log (errorMsg_Device); | |
} | |
*/ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
参考サイト:コマンドラインからビルドする | |
http://qiita.com/tyfkda/items/bfefb4742759af8392c4 | |
ビルドコマンド | |
$ /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath /Users/masayuki5160/Documents/autoBuild -buildTarget android -executeMethod BuildBatch.BuildAndroid -quit | |
↑失敗 | |
参考サイト: UnityPro+Github+Jenkins+DeployGateで自動ビルド&配布環境を作る その1 | |
http://raharu0425.hatenablog.com/entry/2014/12/11/175700 | |
$ /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath /Users/masayuki5160/Documents/autoBuild -executeMethod BuildBatch.BuildiOS -logFile ~/build.log; cat ~/build.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using UnityEditor.iOS.Xcode; | |
using System.IO; | |
// Editor ディレクトリ下にいれておくとXcodeプロジェクトを修正する処理をUnityからかける | |
public class XcodeProjectUpdater | |
{ | |
[PostProcessBuild] | |
static void OnPostprocessBuild(BuildTarget buildTarget, string path) | |
{ | |
if (buildTarget != BuildTarget.iOS) return; | |
var plistPath = Path.Combine(path, "Info.plist"); | |
var plist = new PlistDocument(); | |
plist.ReadFromFile(plistPath); | |
plist.root.SetString("TestEntry", "Hello"); | |
plist.WriteToFile(plistPath); | |
} | |
} |
iOSのビルドがうまくいった
【Unity】バッチモードビルド
http://blog.shonanshachu.com/2013/06/unity.html
これがよくまとまっているぽい?
Xcodeでのプロジェクト設定まわりをUnityで自動化するために...
参考:UnityでのXcode設定をUnityEditorのスクリプトだけで自動化する
http://cflat-inc.hatenablog.com/entry/2015/01/05/074442
上記を参考にしたがどうもUnity5.xからはすでにUnityEditor.iOS.Xcodeは組み込み済みのようだ。
Xcode Manipulation API
https://bitbucket.org/Unity-Technologies/xcodeapi
上記より引用:The API is bundled with Unity 5.x. The documentation of the version bundled with Unity is provided here
PBXProject class in UnityEditor.iOS.Xcode
http://docs.unity3d.com/ScriptReference/iOS.Xcode.PBXProject.html
Unityの方がかいてくれてたー、まだ資料まとまってないのね。。
About Xcode Manipulation API in Unity
https://gist.github.com/keijiro/975b8439d25d58bf62ce
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
上記の方でテストしたらログはでたね.
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath /Users/masayuki5160/Documents/autoBuild -executeMethod BuildBatch.BuildiOS -logFile ~/build.log; cat ~/build.log