1.原理是使用Unity3d的命令行模式,可参考
https://docs.unity3d.com/Manual/CommandLineArguments.html
2.修改settings.properties,增加Unity运行路径
app.version = 1.2.1
unity.bin = /Applications/Unity/Unity.app/Contents/MacOS/Unity
3.修改权限/Applications/Unity/Unity.app/Contents/MacOS/Unity为所有人拥有可读写权限
image.png
4.修改build.xml
<target name="compile-android" depends="clean">
<echo message="Compiling unity project for android version ${VERSION_STRING}"/>
<echo message="${unity.bin} -projectPath ${env.WORKSPACE} -logFile ${env.WORKSPACE}/ant_android_log.txt -buildTarget Android -executeMethod AutoEditor.BuildAndroidResource -batchmode -quit"/>
<exec executable="${unity.bin}" failonerror="true">
<arg line="-projectPath ${env.WORKSPACE}"/>
<arg line="-logFile ${env.WORKSPACE}/ant_android_log.txt"/>
<arg line="-buildTarget Android" />
<arg line="-executeMethod AutoEditor.BuildAndroidResource"/>
<arg line="-batchmode"/>
<arg line="-quit"/>
</exec>
<loadfile property="unity.build.log" srcFile="${env.WORKSPACE}/ant_android_log.txt" encoding="UTF-8"/>
<echo message="${unity.build.log}"/>
</target>
5.如果出现错误,使用Unity3D加载一个工作区的Unity3D工程,看是具体错误原因,本人碰到问题是Unity3D加载工作报只读权限错误,修改workspace为所有人拥有可读写权限
image.png
6.jenkins(詹金斯),控制台输出,调用Unity3D命令行模式成功
网友评论