-
-
Save isaveu/31563ea6ab7f2e93503f15c350759cad to your computer and use it in GitHub Desktop.
Unity + iOS, Android Build Processor for Jenkins
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 System; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
public static class JenkinsBuildProcessor | |
{ | |
[MenuItem("Tools/CI/Build iOS Debug")] | |
public static void BuildIOS() | |
{ | |
// 1. Build Number Automatically Up | |
AddBuildVersion(BuildTarget.iOS); | |
GenericBuild(FindEnabledEditorScenes(), $"./Build/IOS/", BuildTarget.iOS, BuildOptions.None); | |
} | |
[MenuItem("Tools/CI/Build And Debug")] | |
public static void BuildAnd() | |
{ | |
// 1. Build Number Automatically Up | |
var newBuildVersionCode = AddBuildVersion(BuildTarget.Android); | |
PlayerSettings.Android.useCustomKeystore = true; | |
// PlayerSettings.Android.keystoreName = "AndroidKey.keystore"; | |
PlayerSettings.Android.keystorePass = "**KeyStore Password**"; | |
PlayerSettings.Android.keyaliasName = "**Alias name**"; | |
PlayerSettings.Android.keyaliasPass = "**Alias password**"; | |
EditorUserBuildSettings.exportAsGoogleAndroidProject = true; | |
GenericBuild(FindEnabledEditorScenes(), $"./Build/Android/", BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer); | |
} | |
private static string AddBuildVersion(BuildTarget buildTarget) | |
{ | |
CheckBuildTarget(buildTarget); | |
string oldBuildNumber; | |
switch (buildTarget) | |
{ | |
case BuildTarget.Android: | |
oldBuildNumber = PlayerSettings.Android.bundleVersionCode.ToString(); | |
PlayerSettings.Android.bundleVersionCode = (int.Parse(oldBuildNumber) + 1); | |
return PlayerSettings.Android.bundleVersionCode.ToString(); | |
case BuildTarget.iOS: | |
oldBuildNumber = PlayerSettings.iOS.buildNumber; | |
PlayerSettings.iOS.buildNumber = (int.Parse(oldBuildNumber) + 1).ToString(); | |
return PlayerSettings.iOS.buildNumber; | |
break; | |
} | |
return "null"; | |
} | |
private static void CheckBuildTarget(BuildTarget buildTarget) | |
{ | |
if (buildTarget == BuildTarget.Android || buildTarget == BuildTarget.iOS) | |
return; | |
throw new Exception($"Is not supported Platform, {buildTarget}"); | |
} | |
private static void GenericBuild(string[] scenes, string targetPath, BuildTarget buildTarget, BuildOptions buildOptions) | |
{ | |
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget); | |
EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, buildTarget); | |
BuildPipeline.BuildPlayer(scenes, targetPath, buildTarget, buildOptions); | |
} | |
private static string[] FindEnabledEditorScenes() | |
{ | |
List<string> EditorScenes = new List<string>(); | |
foreach(var scene in EditorBuildSettings.scenes) | |
{ | |
if (!scene.enabled) | |
continue; | |
EditorScenes.Add(scene.path); | |
} | |
return EditorScenes.ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment