목차

공통

그냥 복붙용 코드 보는게 나을듯.

빌드용 커맨드

AOS

빌드용 커맨드

맥용 터미널에서 호출하는 예시. 아래는 보기 좋게 줄 구분이 되어 있지만 실제 쓸때는 한줄이어야 함.

-quit -batchmode 
-projectPath $WORKSPACE/my_project
-executeMethod BuildProc.aos_release 
-logFile $WORKSPACE/../_build_/$JOB_BASE_NAME-build-log-$BUILD_NUMBER.txt 
-CustomArgs:buildPath=$WORKSPACE/../_build_/my_project-$BUILD_NUMBER.apk

젠킨스옵션

스크립트

#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEditor.Build.Reporting;
 
// MonoBehaviour 은 없어도 되는듯?
public class BuildProc : MonoBehaviour
{
    // 메뉴에 추가해서 테스트 해볼 수 있게
    [MenuItem("BUILD/AOS - Release")]
    public static void aos_release()
    {
        // CommandLineReader 별도 클래스를 써서, 추가 파라미터를 받아온다.
 
        // 'buildPath'라는 추가 값을 받아서 사용
        string _build_path = CommandLineReader.GetCustomArgument("buildPath");
        Debug.Log("[BLD] all cmdline: " + CommandLineReader.GetCommandLine() + " \n");
        Debug.Log("[BLD] build path: cmdline: " + _build_path + " \n");
 
        // 프로젝트 세팅 외에 이렇게 씬을 직접 넣어야 하는지는 미지수. 테스트 필요.
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/AppMain.unity" };
 
        // 최종 파일을 어디에 저장할 것인가?
        if(_build_path == "") { buildPlayerOptions.locationPathName = "build_aos/make_again.apk"; }
        else { buildPlayerOptions.locationPathName = _build_path; }
 
        Debug.Log("[BLD] build path: final: " + _build_path + " \n");
 
        // 안드로이드용 설정
        buildPlayerOptions.target = BuildTarget.Android;
        buildPlayerOptions.options = BuildOptions.None;
 
        //
        // 안드로이드 빌드할때 필요한 인증키와 암호. 코드 안에서 설정 가능하다. 좋군.
        //
        PlayerSettings.Android.keyaliasName = "my_project";
        PlayerSettings.Android.keyaliasPass = "xxxxxx";
        PlayerSettings.Android.keystoreName = "my_project-key.keystore";
        PlayerSettings.Android.keystorePass = "xxxxxx";
 
        // 빌드 고고
        BuildReport _report = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = _report.summary;
 
        if(summary.result == BuildResult.Succeeded) {
            Debug.Log("Build succeeded: " + summary.totalSize.ToString() + " bytes\n");
        }
        else if(summary.result == BuildResult.Failed) {
            Debug.Log("Build failed\n");
        }
    }
 
    //
    // 나머지 부분은 ios라서 아래쪽에
    //
}

iOS

ios용 빌드는, Xcode용 프로젝트를 export 하는 것으로 작업이 끝난다.

Xcode 빌드는 직접하거나, 외부툴로 빌드가 수행 되도록 설정해야 한다. Jenkins의 xcode 플러그인으로 자동 빌드 가능.

빌드용 커맨드

맥용 터미널에서 호출하는 예시. 아래는 보기 좋게 줄 구분이 되어 있지만 실제 쓸때는 한줄이어야 함.

-batchmode -quit 
-executeMethod BuildProc.ios_release 
-projectPath $WORKSPACE/my_project
-logFile $WORKSPACE/../_xcode_/$JOB_BASE_NAME-build_log-$BUILD_NUMBER.txt 
-CustomArgs:buildPath=$WORKSPACE/../_xcode_/$JOB_BASE_NAME-$BUILD_NUMBER

빌드 파라미터 설명은 위와(빌드용_커맨드1) 같음.

스크립트

{
    [MenuItem("BUILD/iOS - Release")]
    public static void ios_release()
    {
        if(Application.platform != RuntimePlatform.OSXEditor) { Debug.Log("! Run on OSX\n"); return; }
 
        string _build_path = CommandLineReader.GetCustomArgument("buildPath");
        Debug.Log("[BLD] all cmdline: " + CommandLineReader.GetCommandLine() + " \n");
        Debug.Log("[BLD] build path: cmdline: " + _build_path + " \n");
 
        // 씬을 추가해야 하는가? 는 나중에 테스트 해보기로.
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/AppMain.unity" };
 
        if(_build_path == "") { buildPlayerOptions.locationPathName = "./../_build_"; }
        else { buildPlayerOptions.locationPathName = _build_path; }
 
        Debug.Log("[BLD] build path: final: " + _build_path + " \n");
 
        // 개발 플랫폼 설정
        buildPlayerOptions.target = BuildTarget.iOS;
        buildPlayerOptions.options = BuildOptions.None;
 
        // 추가 옵션 없이 바로 빌드 고
        BuildReport _report = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = _report.summary;
 
        if(summary.result == BuildResult.Succeeded) {
            Debug.Log("Build succeeded: " + summary.totalSize.ToString() + " bytes\n");
        }
        else if(summary.result == BuildResult.Failed) {
            Debug.Log("Build failed\n");
        }
    }
}

그외 : CommandLineReader

++++ CommandLineReader.cs (클릭하면 열림) |

CommandLineReader.cs
#region Author
/************************************************************************************************************
Author: EpixCode (Keven Poulin)
Website: http://www.EpixCode.com
GitHub: https://github.com/EpixCode
Twitter: https://twitter.com/EpixCode (@EpixCode)
LinkedIn: http://www.linkedin.com/in/kevenpoulin
************************************************************************************************************/
#endregion
 
#region Copyright
/************************************************************************************************************
Copyright (C) 2013 EpixCode
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************************************************/
#endregion
 
#region Class Documentation
/************************************************************************************************************
Class Name:     CommandLineReader.cs
Namespace:      Com.EpixCode.Util
Type:           Util, Static
Definition:
                CommandLineReader.cs give the ability to access [Custom Arguments] sent 
                through the command line. Simply add your custom arguments under the
                keyword '-CustomArgs:' and seperate them by ';'.
Example:
                C:\Program Files (x86)\Unity\Editor\Unity.exe [ProjectLocation] -executeMethod [Your entrypoint] -quit -CustomArgs:Language=en_US;Version=1.02
 
************************************************************************************************************/
#endregion
 
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#endregion
 
public class CommandLineReader
{
    //Config
    private const string CUSTOM_ARGS_PREFIX = "-CustomArgs:";
    private const char CUSTOM_ARGS_SEPARATOR = '^';
 
    public static string[] GetCommandLineArgs()
    {
        return Environment.GetCommandLineArgs();
    }
 
    public static string GetCommandLine()
    {
        string[] args = GetCommandLineArgs();
 
        if (args.Length > 0)
        {
            return string.Join(" ", args);
        }
        else
        {
            Debug.LogError("CommandLineReader.cs - GetCommandLine() - Can't find any command line arguments!");
            return "";
        }
    }
 
    public static Dictionary<string,string> GetCustomArguments()
    {
        Dictionary<string, string> customArgsDict = new Dictionary<string, string>();
        string[] commandLineArgs = GetCommandLineArgs();
        string[] customArgs;
        string[] customArgBuffer;
        string customArgsStr = "";
 
        try
        {
            customArgsStr = commandLineArgs.Where(row => row.Contains(CUSTOM_ARGS_PREFIX)).Single();
        }
        catch (Exception e)
        {
            Debug.LogError("CommandLineReader.cs - GetCustomArguments() - Can't retrieve any custom arguments in the command line [" + commandLineArgs + "]. Exception: " + e);
            return customArgsDict;
        }
 
        customArgsStr = customArgsStr.Replace(CUSTOM_ARGS_PREFIX, "");
        customArgs = customArgsStr.Split(CUSTOM_ARGS_SEPARATOR);
 
        foreach (string customArg in customArgs)
        {
            customArgBuffer = customArg.Split('=');
            if (customArgBuffer.Length == 2)
            {
                customArgsDict.Add(customArgBuffer[0], customArgBuffer[1]);
            }
            else
            {
                Debug.LogWarning("CommandLineReader.cs - GetCustomArguments() - The custom argument [" + customArg + "] seem to be malformed.");
            }
        }
 
        return customArgsDict;
    }
 
    public static string GetCustomArgument(string argumentName)
    {
        Dictionary<string, string> customArgsDict = GetCustomArguments();
 
        if (customArgsDict.ContainsKey(argumentName))
        {
            return customArgsDict[argumentName];
        }
        else
        {
            Debug.LogError("CommandLineReader.cs - GetCustomArgument() - Can't retrieve any custom argument named [" + argumentName + "] in the command line [" + GetCommandLine() + "].");
            return "";
        }
    }
}

++++