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环境变量中 ...
随机推荐
- Docker入门(二):安装/卸载
这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...
- fastreport整理
Q1:如何直接打印,不显示打印对话框? frxReport1.PrintOptions.ShowDialog := false; frxReport1.PrepareReport(true); frx ...
- 大话Spark(1)-Spark概述与核心概念
说到Spark就不得不提MapReduce/Hadoop, 当前越来越多的公司已经把大数据计算引擎从MapReduce升级到了Spark. 至于原因当然是MapReduce的一些局限性了, 我们一起先 ...
- 苦逼三流小公司程序员这半年找工作经历(3)——选择offer
本文按照企业规模.性质.规模,分成三类,点评一下遇到的这些公司.也算是为半年找工作经历的一个总结. 1,三流小公司 公司规模类似于笔者跳槽前所在企业,性质有外商独资.合资,当然大多数都是民营企业,规模 ...
- Android开发,关于aar你应该知道的
https://yangbo.tech/2015/10/17/all-about-aar/ 背景 在软件工程中,分治是最基本的设计原理,就如同现实中的砖.瓦.钢筋.水泥一样,模块化.组件化的分工,让我 ...
- hdu1688(dijkstra求最短路和次短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题意:第k短路,这里要求的是第1短路(即最短路),第2短路(即次短路),以及路径条数,最后如果最 ...
- 洛谷P3704 [SDOI2017]数字表格(莫比乌斯反演)
传送门 yyb大佬太强啦…… 感觉还是有一点地方没有搞懂orz //minamoto #include<cstdio> #include<iostream> #include& ...
- [Xcode 实际操作]六、媒体与动画-(5)使用CoreImage框架给图片添加马赛克效果
目录:[Swift]Xcode实际操作 本文将演示如何使用CoreImage图像处理框架,给图片添加像素化的滤镜效果. 在项目导航区,打开视图控制器的代码文件[ViewController.swift ...
- Sublime Text 3 最新注册码激活码 和 Sublime Text 2 注册码
Sublime是一款很好用的很轻巧的编辑器,堪称一代神级编辑器.此篇文章用于简单学习记录下神器的激活码,不作其他用途.如有侵权,请联系删除,谢谢~~ 1.官方下载地址: http://www.su ...
- Bootstrap 栅栏布局中 col-xs-*、col-sm-*、col-md-*、col-lg-* 区别及使用方法
(1)概括 一句话概括:根据显示屏幕宽度的大小,自动的选用对应的类的样式. (2)关键字段 1.col是column简写:列: 2.xs是maxsmall简写:超小, ...