unity空格跳跃代码_不看必后悔系列:十分钟教你搭建Jenkins导出Unity安卓环境教程...
发布日期:2021-08-20 05:18:32 浏览次数:44 分类:技术文章

本文共 3553 字,大约阅读时间需要 11 分钟。

3702b24a89892a9aba30acdb8246dfa6.png

前言

想配置一个不同的打包工具,那种可以随时想要一个运行包就可以自己打包看效果,这就要用到本篇给大家分享的搭建Jenkins打包导出Unity安卓环境的教程。

准备工具

准备Jenkins环境,可以选择去Jenkins官网下载,我这里准备了一个Jenkins的war包。

搭建步骤

首要前提本地Unity已经安装好UnityAndroid的打包环境,确保能够正确的用Unity导出Androidapk包,这里就不过多介绍Unity如何导出Android环境了,自行解决。

命令行启动Jenkins,java-jarjenkins.war,会看到如下运行即代表启动成功,可以在浏览器输入http://localhost:8080/来测试,会看到进入Jenkins网站。

4426725ece15028d56437e0a34ead732.png

692412ef7dcf4b3b2c3673ebcc62ca78.png

构建项目

bb96572f09c6101b716948b26307e531.png

6b370eb2b345e178497f2331c0014a9c.png

注意windows路径和命令行的路径的转变,上图是Unity打包apk的批处理的路径,这个批处理如下图,并且要放到Unity的工程下。

d7c8109cb7a77469aa8b5a3e69cc3edb.png

注意:如果批处理路径中不能带有空格,如果有空格的话可以加上双引号,确保这个批处理能够正确的导出apk,批处理代码如下,并且注意用utf8保存:

@echo offecho "Start build apk..."C:"Program Files"Unity1748f1UnityEditorUnity.exe -projectPath D:studygitoschinajenkinsTestHelloUnity -quit -batchmode -executeMethod PerformBuild.CommandLineBuildAndroid -logFile build.logREM %1 -projectPath %2 -quit -batchmode -executeMethod APKBuild.Build -logFile build.logif not %errorlevel%==0 ( goto fail ) else ( goto success ):successecho Build APK OKgoto end:failecho Build APK Failgoto end:endpause

工程Editor目录下添加自动构建的代码:

using UnityEditor;using System.IO;using System.Collections;using UnityEngine;using System.Collections.Generic;class PerformBuild{    static string[] GetBuildScenes()    {        List
names = new List
(); 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 buildn------------------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 versionn------------------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构建

a4090dc5f606e6690dbfa66516992a7f.png

本地生成apk

899a5ccb5c6418e709f0a08152853f0e.png

以上就是搭建Jenkins打包导出Unity安卓环境的全部内容,希望能对大家有所帮助。

转载地址:https://blog.csdn.net/weixin_33501587/article/details/113490096 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python在线翻译脚本_python写的翻译脚本详解
下一篇:mysql数据库数字排序吗_Mysql数据库中关于数字排序问题讲解

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月13日 07时49分07秒