UnityAndroid環境チュートリアルをエクスポートするためのJenkinsのビルド方法を教える10分

序文

別のパッケージツールを構成する場合は、いつでも実行中のパッケージが必要な場合に効果を確認するために自分でパッケージ化できます。これは、この記事で共有するJenkinsパッケージの構築とUnityAndroid環境のエクスポートに関するチュートリアルを使用します。

準備ツール

Jenkins環境を準備するには、Jenkins公式Webサイトからダウンロードすることを選択できます。ここでJenkins戦争パッケージを準備しました。

構築手順

最初の前提は、AndroidapkパッケージをUnityで正しくエクスポートできるように、ローカルのUnityがUnityAndroidパッケージ環境をインストールしていることです。ここでは、UnityがAndroid環境をエクスポートしてそれ自体で解決する方法についてはあまり紹介しません。

コマンドラインjava-jarjenkins.warでJenkinsを起動すると、次の操作が表示されます。これは、起動が成功したことを意味します。ブラウザにhttp:// localhost:8080 /と入力してテストすると、次のように表示されます。 JenkinsのWebサイト。

プロジェクトをビルドする

Windowsパスとコマンドラインパスの変更に注意してください。上の図は、Unityのパッケージapkのバッチ処理のパスです。このバッチ処理は次の図のようになり、Unityプロジェクトの下に配置する必要があります。 。

注:バッチパスにスペースを含めることができない場合、スペースがある場合は、二重引用符を追加して、バッチがapkを正しくエクスポートできるようにすることができます。バッチコードは次のとおりです。utf8に保存するように注意してください。

@echo off
echo "Start build apk..."
C:\"Program Files"\Unity1748f1\Unity\Editor\Unity.exe -projectPath D:\study\gitoschina\jenkinsTest\HelloUnity -quit -batchmode -executeMethod PerformBuild.CommandLineBuildAndroid -logFile build.log
REM %1 -projectPath %2 -quit -batchmode -executeMethod APKBuild.Build -logFile build.log
if not %errorlevel%==0 ( goto fail ) else ( goto success )
:success
echo Build APK OK
goto end
:fail
echo Build APK Fail
goto end
:end
pause

自動的にビルドされたコードをプロジェクトのエディターディレクトリに追加します。

using UnityEditor;
using System.IO;
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
class PerformBuild
{
    static string[] GetBuildScenes()
    {
        List<string> names = new List<string>();
        foreach (EditorBuildSettingsScene e in EditorBuildSettings.scenes)
        {
            if (e == null)
                continue;
            if (e.enabled)
                names.Add(e.path);
        }
        return names.ToArray();
    }
    static string GetBuildPath()
    {
        string dirPath = Application.dataPath + "/../build/iPhone";
        if (!System.IO.Directory.Exists(dirPath))
        {
            System.IO.Directory.CreateDirectory(dirPath);
        }
        return dirPath;
    }
    [UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build iPhone Step")]
    static void CommandLineBuild()
    {
        Debug.Log("Command line build\n------------------\n------------------");
        string[] scenes = GetBuildScenes();
        string path = GetBuildPath();
        if (scenes == null || scenes.Length == 0 || path == null)
            return;
        Debug.Log(string.Format("Path: \"{0}\"", path));
        for (int i = 0; i < scenes.Length; ++i)
        {
            Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
        }
        Debug.Log("Starting Build!");
        BuildPipeline.BuildPlayer(scenes, path, BuildTarget.iOS, BuildOptions.None);
    }
    static string GetBuildPathAndroid()
    {
        string dirPath = Application.dataPath.Replace("/Assets", "") + "/../build/android/"+Application.productName+".apk";
        if (!System.IO.Directory.Exists(dirPath))
        {
            System.IO.Directory.CreateDirectory(dirPath);
        }
        return dirPath;
    }
    [UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build Step Android")]
    static void CommandLineBuildAndroid()
    {
        Debug.Log("Command line build android version\n------------------\n------------------");
        string[] scenes = GetBuildScenes();
        string path = GetBuildPathAndroid();
        if (scenes == null || scenes.Length == 0 || path == null)
        {
            Debug.LogError("Please add scene to buildsetting...");
            return;
        }
        Debug.Log(string.Format("Path: \"{0}\"", path));
        for (int i = 0; i < scenes.Length; ++i)
        {
            Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
        }
        Debug.Log("Starting Android Build!");
        BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.None);
    }
}

Jenkinsビルドをクリックします

ローカルでapkを生成する

上記は、UnityAndroid環境をパッケージ化してエクスポートするためのJenkinsの構築の全内容です。これがすべての人に役立つことを願っています。

おすすめ

転載: blog.csdn.net/bycw666/article/details/123632416