private KeystoreArgs GetKeystoreArgs(string [] args) { KeystoreArgs keystoreArgs = new KeystoreArgs(); for (int i = 0; i < args.Length; i++) { //Check if we encountered a desired option if (args[i] == "--keystore") { keystoreArgs.keyStore = CheckKeystoreArg("--keystore", args[i + 1], keystoreArgs.keyStore); } else if (args[i] == "--storepass") { keystoreArgs.storePass = CheckKeystoreArg("--storepass", args[i + 1], keystoreArgs.storePass); } else if (args[i] == "--keyalias") { keystoreArgs.keyAlias = CheckKeystoreArg("--keyalias", args[i + 1], keystoreArgs.keyAlias); } else if (args[i] == "--keypass") { keystoreArgs.keyPass = CheckKeystoreArg("--keypass", args[i + 1], keystoreArgs.keyPass); } } return(keystoreArgs); }
/// <summary> /// Create a new build /// </summary> /// <param name="target">Desired <see cref="BuildTarget"/> for the build</param> /// <param name="commandLineArguments">Command line arguments passed to Unity</param> public Build(BuildTarget target, string[] commandLineArguments) { //Disable development build setting EditorUserBuildSettings.development = false; //Fetch the target directory from command line arguments string targetDir = GetTargetPath(commandLineArguments); //Check that command line arguments are provided if (string.IsNullOrEmpty(targetDir)) { throw new ArgumentException("[JenkinsBuild] Incorrect arguments for -executeMethod. Missing output directory. Format: -executeMethod <buildclass> <output dir>"); } //Assign a path for build results string buildPath = $"{targetDir}/{target}"; //For testing Debug.Log($"Current working directory: {Directory.GetCurrentDirectory()}"); //Clear the target directory if it exists if (Directory.Exists(buildPath)) { Directory.Delete(buildPath, true); } //Check if we are building for Android if (target == BuildTarget.Android) { //Check if we are creating an Android App Bundle if (EditorUserBuildSettings.buildAppBundle == true) { //Modify the build path so that we create a file to the Android folder with .aab extension buildPath += $"/{PlayerSettings.productName}.aab"; } else { //Modify the build path so that we create a a file to the Android folder with .apk extension buildPath += $"/{PlayerSettings.productName}.apk"; } //Set a keystore for signing the package KeystoreArgs keystoreArgs = GetKeystoreArgs(commandLineArguments); PlayerSettings.Android.useCustomKeystore = true; PlayerSettings.Android.keystoreName = keystoreArgs.keyStore; PlayerSettings.Android.keystorePass = keystoreArgs.storePass; PlayerSettings.Android.keyaliasName = keystoreArgs.keyAlias; PlayerSettings.Android.keyaliasPass = keystoreArgs.keyPass; } //Fetch Scenes to build string[] scenes = FindEditorScenes(); //Build the app BuildPipeline.BuildPlayer(new BuildPlayerOptions { scenes = scenes, target = target, locationPathName = buildPath }); }