Last active
December 5, 2023 12:54
-
-
Save Jawnnypoo/366bbcc7f65e85154a15 to your computer and use it in GitHub Desktop.
Typical Buildscript for Unity on Jenkins. Run with command line args "-quit -batchmode -projectPath ${WORKSPACE} -executeMethod BuildScript.PerformAndroidBuild -logfile /dev/stdout"
This file contains hidden or 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 UnityEditor; | |
using System; | |
using System.Collections.Generic; | |
class BuildScript { | |
static string[] SCENES = FindEnabledEditorScenes(); | |
static string APP_NAME = "AngryBots"; | |
static string TARGET_DIR = "target"; | |
static void PerformAllBuilds () | |
{ | |
PerformMacOSXBuild (); | |
PerformWindowsBuild (); | |
PerformWebStreamingBuild (); | |
PerformWebBuild (); | |
PerformAndroidBuild(); | |
PerformiOSBuild(); | |
} | |
static void PerformMacOSXBuild () | |
{ | |
string target_dir = APP_NAME; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.StandaloneOSXUniversal,BuildOptions.None); | |
} | |
static void PerformWindowsBuild () | |
{ | |
string target_dir = APP_NAME + ".exe"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.StandaloneWindows,BuildOptions.None); | |
} | |
static void PerformLinuxBuild () | |
{ | |
string target_dir = "linux"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.StandaloneLinux,BuildOptions.None); | |
} | |
static void PerformWebStreamingBuild () | |
{ | |
string target_dir = "webstreaming"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.WebPlayerStreamed,BuildOptions.None); | |
} | |
static void PerformWebBuild () | |
{ | |
string target_dir = "web"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.WebPlayer,BuildOptions.None); | |
} | |
static void PerformWebGLBuild () | |
{ | |
string target_dir = "webgl"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.WebGL,BuildOptions.None); | |
} | |
static void PerformAndroidBuild () | |
{ | |
//Set the path to the Android SDK on the machine, since Unity cannot retain the state properly | |
AndroidSDKFolder.Path = "${ANDROID_HOME}"; | |
string target_dir = APP_NAME + ".apk"; | |
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTarget.Android,BuildOptions.None); | |
} | |
static void PerformiOSBuild () | |
{ | |
string target_dir = "iOS"; | |
//We do not build the xcodeproject in the target directory, since we do not want to archive the | |
//entire xcode project, but instead build with XCode, then output the .ipa through Jenkins | |
GenericBuild(SCENES, target_dir, BuildTarget.iOS,BuildOptions.None); | |
} | |
private static string[] FindEnabledEditorScenes() { | |
List<string> EditorScenes = new List<string>(); | |
foreach(EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { | |
if (!scene.enabled) continue; | |
EditorScenes.Add(scene.path); | |
} | |
return EditorScenes.ToArray(); | |
} | |
static void GenericBuild(string[] scenes, string target_dir, BuildTarget build_target, BuildOptions build_options) | |
{ | |
EditorUserBuildSettings.SwitchActiveBuildTarget(build_target); | |
string res = BuildPipeline.BuildPlayer(scenes,target_dir,build_target,build_options); | |
if (res.Length > 0) { | |
throw new Exception("BuildPlayer failure: " + res); | |
} | |
} | |
} |
Hi, where i should locate this file ?
and how to assign a key for Android ?
However, i got obsolete warning, so many errors...
how would one add arkit support?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was super helpful, thanks! I had to put this file inside an
#if (UNITY_EDITOR) ... #endif
block so Unity wouldn't include the script when building.