using UnityEngine; using UnityEditor; using System; using System.IO; using System.Collections.Generic; ////// 命令行批处理工具类 /// public class Batchmode { static Listlevels = new List (); static string keystoreFile = @"D:\keystore.txt"; public static void BuildAndroid() { if(!File.Exists(keystoreFile)) throw new Exception("Not find keystore file"); StreamReader sr = File.OpenText(keystoreFile); string password = sr.ReadToEnd().Trim(); PlayerSettings.Android.keystorePass = password; PlayerSettings.Android.keyaliasPass = password; foreach ( EditorBuildSettingsScene scene in EditorBuildSettings.scenes ) { if ( !scene.enabled ) continue; levels.Add( scene.path ); } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android); string res = BuildPipeline.BuildPlayer( levels.ToArray(), "android.apk", BuildTarget.Android, BuildOptions.None ); if (res.Length > 0) throw new Exception("BuildPlayer failure: " + res); } }
@echo off @set unity="C:\Program Files\Unity\Editor\Unity.exe" echo 正在生成APK文件... %unity% -batchmode -quit -nographics -executeMethod Batchmode.BuildAndroid -logFile D:\Editor.log -projectPath "D:\China\2014-11-12_client_wushen_android" echo APK文件生成完毕! pause
参考:http://blog.csdn.net/jbjwpzyl3611421/article/details/12780439