Unity3d通过脚本生成apk
参考链接:http://www.jianshu.com/p/a9261113b4ac
照着链接的方法并没有正确生成APK,IPA没有测试过,不过大致的方法是正确的,修改如下:
Environment.bat
:: set your own Unity path
set unity="D:\Program Files\Unity\Editor\Unity.exe"
:: -debug or -release
set debugParam=-release set projectPath="E:\mycode\test\testpro"
UnityToApk.bat
call Environment.bat echo "Start Build Unity to Apk" %unity% -batchmode -projectPath %projectPath% -executeMethod CommandBuilder.PreBuild %debugParam% -quit -logFile ./PreBuild.log
%unity% -batchmode -projectPath %projectPath% -executeMethod CommandBuilder.Build %debugParam% -android -quit -logFile ./BuildApk.log echo "End Build,please see log PreBuild.log and BuildApk.log"
cs脚本,放在Editor目录下
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO; public class CommandBuilder { private static string[] build_scenes = { "Assets/ddd.unity" }; private static bool ms_isDebugBuild = false;
private static BuildTarget ms_buildTarget = BuildTarget.Android; private static string XCODE_PROJECT_NAME = "XCodeProject";
private static string BUILD_OUTPUT_ANDROID = Application.dataPath + "/Bin/Android/"; private static void UpdateBuildFlag()
{
string[] args = System.Environment.GetCommandLineArgs();
foreach (string oneArg in args)
{
if (oneArg != null && oneArg.Length > )
{
if (oneArg.ToLower().Contains("-debug"))
{
Debug.Log("\"-debug\" is detected, switch to debug build.");
ms_isDebugBuild = true;
return;
}
else if (oneArg.ToLower().Contains("-release"))
{
Debug.Log("\"-release\" is detected, switch to release build.");
ms_isDebugBuild = false;
return;
}
}
} if (ms_isDebugBuild)
{
Debug.Log("neither \"-debug\" nor \"-release\" is detected, current is to debug build.");
}
else
{
Debug.Log("neither \"-debug\" nor \"-release\" is detected, current is to release build.");
} } private static void UpdateBuildTarget()
{
string[] args = System.Environment.GetCommandLineArgs();
foreach (string oneArg in args)
{
if (oneArg != null && oneArg.Length > )
{
if (oneArg.ToLower().Contains("-android"))
{
Debug.Log("\"-android\" is detected, switch build target to android.");
ms_buildTarget = BuildTarget.Android;
return;
}
else if (oneArg.ToLower().Contains("-iphone"))
{
Debug.Log("\"-iphone\" is detected, switch build target to iphone.");
ms_buildTarget = BuildTarget.iOS;
return;
}
else if (oneArg.ToLower().Contains("-ios"))
{
Debug.Log("\"-ios\" is detected, switch build target to iphone.");
ms_buildTarget = BuildTarget.iOS;
return;
}
}
} Debug.Log("neither \"-android\", \"-ios\" nor \"-iphone\" is detected, current build target is: " + ms_buildTarget);
} public static void PreBuild()
{
Debug.Log("PreBuild");
UpdateBuildFlag();
}
public static void Build()
{
Debug.Log("Build");
UpdateBuildTarget(); BuildOptions buildOption = BuildOptions.None;
if (ms_isDebugBuild)
{
buildOption |= BuildOptions.Development;
buildOption |= BuildOptions.AllowDebugging;
buildOption |= BuildOptions.ConnectWithProfiler;
}
else
{
buildOption |= BuildOptions.None;
} string locationPathName;
if (BuildTarget.iOS == ms_buildTarget)
{
locationPathName = XCODE_PROJECT_NAME;
}
else
{
locationPathName = BUILD_OUTPUT_ANDROID; //原链接此处没有生成目录,而是使用rmdir mkdir生成,实际测试时无法将APK复制进目录中,所以讲目录修改如下
if (Directory.Exists(locationPathName))
Directory.Delete(locationPathName, true); Directory.CreateDirectory(locationPathName); System.DateTime time = System.DateTime.Now;
locationPathName += "test_" + time.Month.ToString("D2") + time.Day.ToString("D2") +
"_" + time.Hour.ToString("D2") + time.Minute.ToString("D2") + ".apk";
}
BuildPipeline.BuildPlayer(build_scenes, locationPathName, ms_buildTarget, buildOption);
}
public static void PostBuild()
{
Debug.Log("PostBuild");
} }
Unity3d通过脚本生成apk的更多相关文章
- Unity3D研究院之脚本生成Android Google Project
一般安卓自动化打包直接会生成个APK出来,但是我不想生成APK,我想生成Eclipse项目. 然后在自动化完成后面的打包工作. 1 2 3 4 5 6 7 8 9 10 11 using Un ...
- windows下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
原创文章,转载请注明:http://www.cnblogs.com/ycxyyzw/p/4535459.html android 程序打包成apk,如果在是命令行方式,一般都要经过如下步骤: 1.用a ...
- unity3d进行脚本资源打包加载
原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...
- 【转】eclipse android 设置及修改生成apk的签名文件 -- custom debug keystore
原文网址:http://hold-on.iteye.com/blog/2064642 android eclipse 设置及修改生成apk的签名文件 1. 问题: 平时在使用eclipse进行andr ...
- Unity3D批处理脚本
Unity3D批处理脚本 本文属于转载,如有侵权,请留言,我会及时删除! Max09在模型到处的模型和U3D场景的尺寸不一致,Max09中的1m导到U3D中,只有0.01m,这时可以在U3D中将模型的 ...
- 快速生成apk 自动发布到网站 便于测试
遇到的问题: 开发者生成的apk 需要不断给 测试安装让他们测试.有没有脚本自动将最新apk上传到服务器,让测试自己安装测试呢?mac电脑 怎么自己搭建文件服务器 启动Tomcat功能在这里不在赘述 ...
- 【转】Unity3D中脚本的执行顺序和编译顺序
支持原文,原文请戳: Unity3D中脚本的执行顺序和编译顺序 在Unity中可以同时创建很多脚本,并且可以分别绑定到不同的游戏对象上,它们各自都在自己的生命周期中运行.与脚本有关的也就是编译和执行啦 ...
- 打包成apk,生成apk文件,上传到网站服务器提供链接下载
Android开发把项目打包成apk: 做完一个Android项目之后,如何才能把项目发布到Internet上供别人使用呢?我们需要将自己的程序打包成Android安装包文件--APK(Android ...
- Jenkins生成APK链接的二维码
Window环境 1.下载安装Python如3.7.5版本,安装Python到电脑上如C:\Python37,将C:\Python37,C:\Python37\Scripts添加到Path环境变量中 ...
随机推荐
- ssh无密码登录设置失败的 解决办法
因为要安装hadoop所以需要设置ssh无密码登录,SSH的安装就不在这里介绍了: 我的系统是ubuntu15.10,开始按照网上很多的步骤去配置,最后发现登录时还要密码,登录多次也是这样的情况 最后 ...
- IE各栏的截图说明
工具栏 包括 状态栏 命令栏 菜单栏 收藏栏 IE工具 > 工具栏 > 状态栏 有状态栏显示 无状态栏显示 菜单栏 快捷键 alt 可以快速展示 菜单栏 ,查看 ...
- Deep Learning - Install the Development Environment
WLS(Windows Subsystem for Linux) Base WLS Installation Guide Initializing a newly installed distro W ...
- 读取静态Json文件
创建web项目: string Json = string.Empty; string filePath = Server.MapPath("/***.json");//根目录下的 ...
- 通过ssh X11转发使用远程gui程序
ssh协议可以转发X11数据, 从而达到使用远程gui程序的功能, 假定现在有 客服端 C :192.168.0.13 服务器 S :192.168.0.200 首先确保在客服端C 上能够通过 ssh ...
- 在Packstack环境手动安装OVN
安装OpenStack(allinone)环境 ### 参考"Packstack使用"章节安装,但是不要配置外网网络 安装OVN组件 ### 控制节点 # yum install ...
- SVN版本控制图标未显示或显示异常解决方法
SVN版本控制图标未显示问题解决方法,刚开始遇到这个问题的时候,好苦恼.经过“千辛万苦”的努力,终于得以解决,分享给大家,希望能帮到各位哦! 工具/原料 SVN安装包 方法/步骤 首先安装 ...
- [UE4]C++设置AnimInstance的相关问题
注意:ue4 4.17调用LoadObject<UAnimBlueprintGeneratedClass>直接崩 http://aigo.iteye.com/blog/2285001 UA ...
- sticky,粘性定位
position:sticky,粘性定位:可以说是relative和fixed的结合: 滑动过程中,元素在显示窗口内则在其本身的位置,超出元素所在位置则显示在设定的sticky位置. 使用: #id ...
- 外网连接Mysql云数据库
购买好Mysql云数据库,这里是腾讯云 在管理中把外网地址开通,然后可以看到本云数据库的外网地址 注意:外网地址com到前面才是连接地址,冒号后面的10057是连接的端口号,可以看下面的连接语句 cm ...