├── ProjectBuild.cs
├── build.sh
├── buildforAndroid.sh
├── buildforios.sh
└── readme.md
/ProjectBuild.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 | using UnityEditor;
5 | using UnityEditor.SceneManagement;
6 | using System.IO;
7 | using System;
8 |
9 |
10 | public class ProjectBuild
11 | {
12 | ///
13 | /// 所有要打包的场景
14 | ///
15 | /// The get build scenes.
16 | static string[] GetBuildScenes
17 | {
18 | get
19 | {
20 | List list = new List();
21 | foreach (EditorBuildSettingsScene es in EditorBuildSettings.scenes)
22 | {
23 | if (es != null && es.enabled)
24 | {
25 | string fileName = Path.GetFileNameWithoutExtension(es.path);
26 | if (!fileName.Contains("Transfer"))
27 | {
28 | list.Add(es.path);
29 | }
30 | }
31 | }
32 | return list.ToArray();
33 | }
34 | }
35 | static string[] GetTransBuildScenes
36 | {
37 | get
38 | {
39 | List list = new List();
40 | foreach (EditorBuildSettingsScene es in EditorBuildSettings.scenes)
41 | {
42 | if (es != null && es.enabled)
43 | {
44 | string fileName = Path.GetFileNameWithoutExtension(es.path);
45 | if (fileName.Contains("Transfer"))
46 | {
47 | list.Add(es.path);
48 | }
49 |
50 | //list.Add(es.path);
51 | }
52 |
53 | }
54 | return list.ToArray();
55 | }
56 | }
57 |
58 | static Dictionary buildGames
59 | {
60 | get
61 | {
62 | Dictionary dic = new Dictionary();
63 | string[] strs = System.Environment.GetCommandLineArgs();
64 | foreach (string str in strs)
65 | {
66 | if (str.StartsWith("buildgmaes"))
67 | {
68 | string buildgmaes = str.Replace("buildgmaes=", "");
69 | string[] builds = buildgmaes.Split('|');//.Replace("version=", "");
70 | foreach (string build in builds)
71 | {
72 | string[] bs = build.Split('=');
73 | dic[bs[0]] = bool.Parse(bs[1]);
74 | }
75 | }
76 | }
77 | return dic;
78 | }
79 | }
80 |
81 | static BuildTargetGroup CurrenBuildTarget
82 | {
83 | get
84 | {
85 | string[] strs = System.Environment.GetCommandLineArgs();
86 | foreach (string str in strs)
87 | {
88 | if (str.StartsWith("type"))
89 | {
90 | string stra = str.Replace("type=", "");
91 |
92 | switch (stra)
93 | {
94 | case "AND":
95 | return BuildTargetGroup.Android;
96 | case "IOS":
97 | return BuildTargetGroup.iOS;
98 | default:
99 | return BuildTargetGroup.Android;
100 | }
101 | }
102 | }
103 | return BuildTargetGroup.Android;
104 | }
105 | }
106 |
107 | private static string mDefVersion = "9.0.0";
108 | public static string version
109 | {
110 | get
111 | {
112 | string[] strs = System.Environment.GetCommandLineArgs();
113 | foreach (string str in strs)
114 | {
115 | if (str.StartsWith("version"))
116 | {
117 | return str.Replace("version=", "");
118 | }
119 |
120 | }
121 | return mDefVersion;
122 | }
123 | }
124 |
125 | private static string mInstallVersion = "1.0.0";
126 | public static string InstallVersion
127 | {
128 | get
129 | {
130 | string[] strs = System.Environment.GetCommandLineArgs();
131 | foreach (string str in strs)
132 | {
133 | if (str.StartsWith("InstallVersion"))
134 | {
135 | return str.Replace("InstallVersion=", "");
136 | }
137 |
138 | }
139 | return mInstallVersion;
140 | }
141 | }
142 |
143 | ///
144 | /// 获取资源版本号
145 | ///
146 | ///
147 | public static string Getversion(string resName)
148 | {
149 | return version;
150 | }
151 |
152 | private static bool misPublic = false;
153 | ///
154 | /// 是否是发布版本
155 | ///
156 | public static bool isPublic
157 | {
158 | get
159 | {
160 | string[] strs = System.Environment.GetCommandLineArgs();
161 | foreach (string str in strs)
162 | {
163 | if (str.StartsWith("ispublic"))
164 | {
165 | return bool.Parse(str.Replace("ispublic=", ""));
166 | }
167 |
168 | }
169 | return misPublic;
170 | }
171 | }
172 |
173 | ///
174 | /// 生成到到路径
175 | ///
176 | /// The outpath.
177 | static string outpath
178 | {
179 | get
180 | {
181 | string[] strs = System.Environment.GetCommandLineArgs();
182 | foreach (string str in strs)
183 | {
184 | if (str.StartsWith("outpath"))
185 | {
186 | return str.Replace("outpath=", "");
187 | }
188 | }
189 | string url = Path.GetFullPath(Application.dataPath + "/../Release");
190 | #if UNITY_IOS
191 | return url+"/pro";
192 | #elif UNITY_ANDROID
193 | return url + "/1.apk";
194 | #else
195 | return url +"/1.exe";
196 | #endif
197 | }
198 | }
199 |
200 |
201 | public enum ChannelType
202 | {
203 | Other = 1,
204 | AppStore,
205 | }
206 |
207 | public enum CollectionType
208 | {
209 | DSMJ = 8002,
210 | SQMJ = 8003,
211 | PXMJ = 8004,
212 | TEST = 1001,
213 | }
214 |
215 | static bool Trans
216 | {
217 | get
218 | {
219 | string[] strs = System.Environment.GetCommandLineArgs();
220 | foreach (string str in strs)
221 | {
222 | if (str.StartsWith("Trans"))
223 | {
224 | string channelStr = str.Replace("Trans=", "");
225 | return bool.Parse(channelStr);
226 | }
227 | }
228 | return false;
229 | }
230 | }
231 | static CollectionType currentCollection
232 | {
233 | get
234 | {
235 | string[] strs = System.Environment.GetCommandLineArgs();
236 | foreach (string str in strs)
237 | {
238 | if (str.StartsWith("Collection"))
239 | {
240 | string channelStr = str.Replace("Collection=", "");
241 | CollectionType type =(CollectionType)Enum.Parse(typeof(CollectionType), channelStr);
242 | return type;
243 | }
244 | }
245 | return CollectionType.TEST;
246 | }
247 | }
248 |
249 | ///
250 | /// 渠道类型
251 | ///
252 | static int Channel
253 | {
254 | get
255 | {
256 |
257 | string[] strs = System.Environment.GetCommandLineArgs();
258 | foreach (string str in strs)
259 | {
260 | if (str.StartsWith("channel"))
261 | {
262 | string channelStr = str.Replace("channel=", "");
263 | if(channelStr == "Other")
264 | {
265 | return (int)ChannelType.Other;
266 | }
267 | else if (channelStr == "AppStore")
268 | {
269 | return (int)ChannelType.AppStore;
270 | }
271 | }
272 | }
273 | return (int)ChannelType.Other;
274 | }
275 | }
276 |
277 | public static void ClearLuaFiles()
278 | {
279 | //ToLuaMenu.ClearLuaFiles();
280 | }
281 |
282 | public static void GenLuaAll()
283 | {
284 | //ToLuaMenu.GenLuaAll();
285 | }
286 |
287 |
288 |
289 | //[UnityEditor.MenuItem("Tools/bulid")]
290 | public static void BuildProjected()
291 | {
292 | Debug.LogError("生成AB");
293 | string assetName = Trans ? (int)currentCollection + "Trans" : (int)currentCollection+"";
294 | assetName += ".asset";
295 | //BuildCollectionResInfo builfCfg = null;
296 | string buildCfgpath = "Assets/YKFramwork/Editor/BuildAbInfo/Collections/"
297 | + assetName;
298 |
299 |
300 | Debug.Log("生成ab完成");
301 | Debug.Log("准备生成APK");
302 | //BuildAB.BuildAb();
303 | if (CurrenBuildTarget == BuildTargetGroup.Android)
304 | {
305 | BuildForAndroid();
306 | }
307 | else if (CurrenBuildTarget == BuildTargetGroup.iOS)
308 | {
309 | BuildForIos();
310 | }
311 | else if (CurrenBuildTarget == BuildTargetGroup.Standalone)
312 | {
313 |
314 | }
315 |
316 |
317 | }
318 |
319 |
320 | public static void DelectDir(string srcPath)
321 | {
322 | try
323 | {
324 | DirectoryInfo dir = new DirectoryInfo(srcPath);
325 | FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
326 | foreach (FileSystemInfo i in fileinfo)
327 | {
328 | if (i is DirectoryInfo) //判断是否文件夹
329 | {
330 | DirectoryInfo subdir = new DirectoryInfo(i.FullName);
331 | subdir.Delete(true); //删除子目录和文件
332 | }
333 | else
334 | {
335 | File.Delete(i.FullName); //删除指定文件
336 | }
337 | }
338 | }
339 | catch (Exception e)
340 | {
341 | throw;
342 | }
343 | }
344 |
345 |
346 | [MenuItem("Tools/Test")]
347 | public static void BuildDSMJ()
348 | {
349 | Debug.LogError(GetBuildScenes);
350 | //mBuildHall = true;
351 | //mIsBuilddsmj = true;
352 | // string path = "Assets/YKFramwork/Editor/BuildAbInfo/Collections/" + 8002 + ".asset";
353 | // BuildCollectionResInfo builfCfg = AssetDatabase.LoadAssetAtPath(path);
354 | // SetUmengXinXI(builfCfg);
355 | }
356 |
357 |
358 |
359 | public static void BuildForAndroid()
360 | {
361 | Debug.LogError("BuildForAndroid>>start");
362 |
363 | PlayerSettings.Android.useAPKExpansionFiles = false;
364 | PlayerSettings.Android.keystoreName = Application.dataPath + "/../xlkj.keystore";
365 | PlayerSettings.Android.keyaliasPass = "xlkj13nk";
366 | PlayerSettings.Android.keystorePass = "xlkj13nk";
367 | PlayerSettings.Android.keyaliasName = "yanshi";
368 |
369 | //PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, buildInfo.AndroidPackageName);
370 | string[] scenes = null;
371 | // if (buildInfo.isTrans)
372 | // {
373 | // scenes = GetTransBuildScenes;
374 | // PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
375 | // }
376 | // else
377 | {
378 | scenes = GetBuildScenes;
379 | PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel22;
380 | }
381 | string res = BuildPipeline.BuildPlayer(scenes, outpath, BuildTarget.Android, BuildOptions.None);
382 | Debug.Log("生成完成"+ res);
383 | Debug.LogError("BuildForAndroid>>end");
384 |
385 | }
386 |
387 | #region 设置xml信息
388 | public static void SetUPushMainnifestxml()
389 | {
390 | // string mainnifestRoot = Application.dataPath + "/Plugins/Android/push.plugin/AndroidManifest.xml";
391 | // string mainnifestMode = Application.dataPath + "/../AndroidXMLMode/UpushManifest.xml";
392 | //
393 | // string mainnifestxml = File.ReadAllText(mainnifestMode);
394 | // Debug.LogError("SetUPushMainnifestxml-> mainnifestxml="+ mainnifestxml);
395 | // mainnifestxml = mainnifestxml
396 | // .Replace("${applicationId}", buildInfo.AndroidPackageName);
397 | //
398 | // Debug.LogError("SetUPushMainnifestxml-> Replace =" + mainnifestxml);
399 | //
400 | // File.WriteAllText(mainnifestRoot, mainnifestxml);
401 | }
402 |
403 | public static void SetBaseMainnifestXml()
404 | {
405 | // string appid = WXConstant.UMengAppID[buildInfo.CollectionID];
406 | // string Secret = WXConstant.UMengPushSecret[buildInfo.CollectionID];
407 | // string channelstr = ((ChannelType)Channel).ToString();
408 | // string mainnifestRoot = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
409 | // string mainnifestMode = Application.dataPath + "/../AndroidXMLMode/AndroidManifest.xml";
410 | // string mainnifestxml = File.ReadAllText(mainnifestMode);
411 | // mainnifestxml = mainnifestxml.Replace("#packageName#", buildInfo.AndroidPackageName)
412 | // .Replace("#UMENG_APPKEY", appid)
413 | // .Replace("#UMENG_MESSAGE_SECRET", Secret)
414 | // .Replace("#UMENG_CHANNEL", channelstr)
415 | // .Replace("#JUMPALIPAYSCHEME", buildInfo.jumpScheme);
416 | // File.WriteAllText(mainnifestRoot, mainnifestxml);
417 | }
418 | #endregion
419 |
420 | #region 设置umeng信息
421 | private class UMConstantInfo
422 | {
423 | public string appid;
424 | public string secret;
425 | public string channelid;// = channelstr
426 | }
427 | public static void SetUmengXinXI()
428 | {
429 | // string appid = WXConstant.UMengAppID[buildInfo.CollectionID];
430 | // string Secret = WXConstant.UMengPushSecret[buildInfo.CollectionID];
431 | // string channelstr = ((ChannelType)Channel).ToString();
432 | // UMConstantInfo uMConstantInfo = new UMConstantInfo();
433 | // uMConstantInfo.appid = appid;
434 | // uMConstantInfo.secret = Secret;
435 | // uMConstantInfo.channelid = channelstr;
436 | // string json= JsonUtility.ToJson(uMConstantInfo);
437 | // File.WriteAllText(Application.streamingAssetsPath + "/UMConstant.json", json);
438 | }
439 | #endregion
440 | public static void BuildForIos()
441 | {
442 | string assetName = (int)currentCollection + "";
443 | // if (buildCfg.isTrans)
444 | // {
445 | // assetName += "Trans";
446 | // }
447 | // else
448 | // {
449 | // if(Channel == (int)ChannelType.AppStore)
450 | // {
451 | // assetName += "Appstore";
452 | // }
453 | // }
454 |
455 | PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.IL2CPP);
456 | PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 2);
457 | // if (Channel == (int)ChannelType.AppStore)
458 | // {
459 | // PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildCfg.IOSAppStorePackName);
460 | // }
461 | // else
462 | // {
463 | // PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildCfg.IOSPackName);
464 | // }
465 | PlayerSettings.iOS.appInBackgroundBehavior = iOSAppInBackgroundBehavior.Custom;
466 | PlayerSettings.iOS.backgroundModes = iOSBackgroundMode.Audio|iOSBackgroundMode.RemoteNotification;
467 |
468 |
469 |
470 | string[] scenes = null;
471 |
472 | scenes = GetBuildScenes;
473 | #if UNITY_IOS
474 | PlayerPrefs.SetString(XcodeProjectUpdater.SETTING_DATA_PATHKEY, "Assets/YKFramwork/Editor/AutoBuild/" + assetName);
475 | PlayerSettings.iOS.allowHTTPDownload = true;
476 | PlayerSettings.iOS.appleEnableAutomaticSigning = false;
477 | string res = BuildPipeline.BuildPlayer(scenes, outpath, BuildTarget.iOS, BuildOptions.None);
478 | #endif
479 | }
480 |
481 | ///
482 | /// 设置背景图和icon
483 | ///
484 | /// 合集id
485 | //[MenuItem("Tools/setIcon")]
486 | public static void SetIconAndBg()
487 | {
488 |
489 | string[] strs = System.Environment.GetCommandLineArgs();
490 | System.Text.StringBuilder sb = new System.Text.StringBuilder();
491 | sb.AppendLine(Channel.ToString());
492 | sb.AppendLine(isPublic.ToString());
493 | File.WriteAllText(Application.dataPath + "/Resources/buildversioninfo.bytes", sb.ToString());
494 |
495 | PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
496 | PlayerSettings.bundleVersion = InstallVersion;
497 | PlayerSettings.SplashScreen.show = false;
498 | PlayerSettings.stripEngineCode = false;
499 | PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;
500 |
501 | PlayerSettings.allowedAutorotateToLandscapeLeft = true;
502 | PlayerSettings.allowedAutorotateToLandscapeRight = true;
503 | PlayerSettings.allowedAutorotateToPortrait = false;
504 | PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
505 |
506 | PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, true);
507 | PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.iOS, true);
508 | string root = Application.dataPath +"/CollectionEeefctRes";
509 |
510 | // Texture2D icon = AssetDatabase.LoadAssetAtPath(FileUtil.GetProjectRelativePath(iconRoot));
511 | // Texture2D[] androidIcons = new Texture2D[6];
512 | // for (int i = 0; i < androidIcons.Length; i++)
513 | // {
514 | // androidIcons[i] = icon;
515 | // }
516 | // Texture2D[] iosIcons = new Texture2D[18];
517 | // for (int i = 0;i< iosIcons.Length;i++)
518 | // {
519 | // iosIcons[i] = icon;
520 | // }
521 | // Texture2D[] pcIcons = new Texture2D[7];
522 | // for (int i = 0;i< pcIcons.Length;i++)
523 | // {
524 | // pcIcons[i] = icon;
525 | // }
526 | //AssetDatabase.CopyAsset()
527 |
528 | //PlayerSettings.productName = buildInfo.CollectionName;
529 | PlayerSettings.companyName = "游客学院";
530 | // PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Standalone, pcIcons);
531 | // PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, androidIcons);
532 | // PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.iOS, iosIcons);
533 | AssetDatabase.Refresh();
534 | }
535 | }
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | export unity=/Applications/Unity/Unity.app/Contents/MacOS/Unity
2 | export logFile=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/log
3 | export buildROOT=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/project
4 | export workspace=/Users/liulianbuxiangkafeibuku/.jenkins/workspace/newdsmj
5 | buildforAndorid=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/buildforAndroid.sh
6 | buildforIos=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/buildforios.sh
7 | workspace=${workspace}/${BUILD_NUMBER}_${version}
8 |
9 | if [ ! -d "$workspace" ];then
10 | mkdir -p $workspace
11 | fi
12 |
13 | echo "$BUILD_NUMBER"
14 | echo "开始生成包";
15 | for a in $*
16 | do
17 | r=`echo $a | sed "s/--//g"`
18 | eval $r
19 | done
20 |
21 | echo "version = $version"
22 | echo "InstallVersion = $InstallVersion"
23 | echo "channel = $channel"
24 | echo "Collection = $Collection"
25 | echo "ispublic = $ispublic"
26 | echo "Trans = $Trans"
27 |
28 | if [ "$platform" = "AND" ]; then
29 | echo "准备生成android版本"
30 | bash $buildforAndorid $version $ispublic $Collection $InstallVersion
31 | elif [ "$platform" = "IOS" ];then
32 | echo "准备生成ios版本"
33 | bash $buildforIos $version $ispublic $Collection $InstallVersion
34 | else
35 | echo "准备生成所有的包"
36 | bash $buildforAndorid $version $ispublic $Collection $InstallVersion
37 | bash $buildforIos $version $ispublic $Collection $InstallVersion
38 | fi
39 |
--------------------------------------------------------------------------------
/buildforAndroid.sh:
--------------------------------------------------------------------------------
1 | android=/Users/liulianbuxiangkafeibuku/Documents/android-sdk/tools/android
2 | androidProjectName="游客学院"
3 | echo "开始生成安卓版本"
4 |
5 | echo "version = $version"
6 | echo "InstallVersion = $InstallVersion"
7 | echo "channel = $channel"
8 | echo "Collection = $Collection"
9 | echo "ispublic = $ispublic"
10 | projectPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/project/and/Project
11 | allresFiles=/Users/liulianbuxiangkafeibuku/Documents/zip
12 | fileName=`date '+%Y%m%d%H%M%S'`
13 | if [ ! -d "${workspace}/AND" ]; then
14 | mkdir -p ${workspace}/AND
15 | fi
16 | ipaname=${fileName}${RANDOM}.apk
17 | #if [ -d "$outpath" ]; then
18 | #rm -rf ${outpath}/*
19 | #else
20 | #mkdir -p $outpath
21 | #fi
22 | outpath=${workspace}/AND/${fileName}.apk
23 |
24 | cd $projectPath
25 | svn revert -R .
26 | svn status | grep '^a?' | sed -e 's/^.//' | xargs rm
27 | svn status | grep '^aM' | sed -e 's/^.//' | xargs rm
28 | svn up
29 |
30 | if [ -d "${projectPath}/Assets/StreamingAssets" ]; then
31 | rm -rf ${projectPath}/Assets/StreamingAssets/*
32 | fi
33 |
34 | if [ -d "${projectPath}/Assets/Source/Generate" ]; then
35 | rm -rf ${projectPath}/Assets/Source/Generate/*
36 | else
37 | mkdir -p ${projectPath}/Assets/Source/Generate/*
38 | fi
39 |
40 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}.log -executeMethod ProjectBuild.ClearLuaFiles
41 |
42 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}.log -executeMethod ProjectBuild.GenLuaAll
43 |
44 |
45 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}.log -executeMethod ProjectBuild.BuildProjected version="$version" InstallVersion="$InstallVersion" type="AND" channel="$channel" Collection="$Collection" outpath="$outpath" ispublic="$ispublic" Trans="$Trans"
46 | if [ -d $allresFiles ]; then
47 | rm -rf ${allresFiles}/*
48 | fi
49 | if [ -d "${projectPath}/Assets/StreamingAssets" ]; then
50 | cp -f ${projectPath}/Assets/StreamingAssets/*.bytes ${projectPath}/Assets/StreamingAssets/*.txt $allresFiles
51 | zip -r ${workspace}/AND/res.zip $allresFiles/*
52 | fi
53 | #cd $outpath
54 | #echo "开始生成 apk包 time: `date '+%Y%m%d%H%M%S'`"
55 | #ls | while read line
56 | #do
57 | #$android update project -p $line/ -t 2
58 | #done
59 |
60 | #cd ${outpath}/${androidProjectName}
61 | #cp ${buildROOT}/fsmj.keystore ${outpath}/${androidProjectName}/fsmj.keystore
62 | #cp ${buildROOT}/ant.properties ${outpath}/${androidProjectName}/ant.properties
63 | #$ant clean
64 | #$ant release
65 |
66 | #echo ${workspace}/${fileName}.apk
67 | #if [ -f "${outpath}/${androidProjectName}/bin/UnityPlayerActivity-release.apk" ]; then
68 | #echo "文件存在"
69 | #cp ${outpath}/${androidProjectName}/bin/UnityPlayerActivity-release.apk ${workspace}/${fileName}.apk
70 | #else
71 | #echo "${outpath}/${androidProjectName}/bin/UnityPlayerActivity-release.apk"
72 | #echo "文件不存在"
73 | #fi
74 |
--------------------------------------------------------------------------------
/buildforios.sh:
--------------------------------------------------------------------------------
1 | echo "开始生成IOS版本"
2 | fileName=`date '+%Y%m%d%H%M%S'`
3 | ipaname=${fileName}${RANDOM}
4 | projectPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/project/ios/Project
5 |
6 |
7 | ExportOptionsTranPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/ExportOptionsTran.plist
8 | PXExportOptionsPlistPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/PXExportOptions.plist
9 | PXExportOptionsPlistTranPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/PXExportOptionsTran.plist
10 | SQExportOptionsPlistPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/SQExportOptions.plist
11 | AppStoreExportOptionsPath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/AppStoreExportOptions.plist
12 | outpath=/Users/liulianbuxiangkafeibuku/Documents/BuildProject/NewBuild/project/ios/out
13 | SignUUID="Your SignUUID"
14 | CODE_SIGN_IDENTITYStr="iPhone Distribution:xxxx"
15 | if [ ! -d "${workspace}/IOS" ]; then
16 | mkdir -p ${workspace}/IOS
17 | fi
18 | ipaPath=${workspace}/IOS/${fileName}.ipa
19 | allresFiles=/Users/liulianbuxiangkafeibuku/Documents/zip
20 | cd $projectPath
21 | svn revert -R .
22 | #恢复所有冲突
23 | #svn st | while read line
24 | #do
25 | #p1=`echo $line | awk '{print $1}'`
26 | #p2=`echo $line | awk '{print $2}'`
27 | #if [ "$p2" == "C" ];then
28 | #echo $line
29 | #file=`echo "$line" | sed "s/^$p1 $p2 //"`
30 | #echo "$file"
31 | #svn revert "$file@"
32 | #fi
33 | #done
34 |
35 | #恢复所有修改
36 | #svn st | while read line
37 | #do
38 | #state=`echo $line | awk '{print $1}'`
39 | #file=`echo $line | awk '{print $2}'`
40 | #if [ "$state" == "D" ];then
41 | #echo $file
42 | #svn revert "$file@"
43 | #fi
44 | #done
45 |
46 | #恢复所有修改
47 | #svn st | while read line
48 | #do
49 | #state=`echo $line | awk '{print $1}'`
50 | #file=`echo $line | awk '{print $2}'`
51 | #if [ "$state" == "M" ];then
52 | #echo $file
53 | #svn revert "$file@"
54 | #fi
55 | #done
56 | svn up
57 |
58 | if [ -d "$projectPath" ]; then
59 | rm -rf ${outpath}/*
60 | else
61 | mkdir -p $outpath
62 | fi
63 |
64 | if [ -d "${projectPath}/Assets/StreamingAssets" ]; then
65 | rm -rf ${projectPath}/Assets/StreamingAssets/*
66 | fi
67 |
68 | if [ -d "${projectPath}/Assets/Source/Generate" ]; then
69 | rm -rf ${projectPath}/Assets/Source/Generate/*
70 | else
71 | mkdir -p ${projectPath}/Assets/Source/Generate/*
72 | fi
73 |
74 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}.log -executeMethod ProjectBuild.ClearLuaFiles
75 |
76 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}_GenLuaAll.log -executeMethod ProjectBuild.GenLuaAll
77 |
78 | $unity -quit -batchmode -projectPath $projectPath -logFile ${logFile}/${ipaname}_BuildProjected.log -executeMethod ProjectBuild.BuildProjected version="$version" InstallVersion="$InstallVersion" type="IOS" channel="$channel" Collection="$Collection" outpath="$outpath" ispublic="$ispublic" Trans="$Trans"
79 | echo "生成Xcode完成准备生成ipa"
80 | cd $outpath
81 | xcodebuild clean
82 |
83 | security unlock-keychain -p "123456" ~/Library/Keychains/login.keychain
84 | if [ -d $allresFiles ]; then
85 | rm -rf ${allresFiles}/*
86 | fi
87 |
88 | if [ -d "${projectPath}/Assets/StreamingAssets" ]; then
89 | cp -f ${projectPath}/Assets/StreamingAssets/*.bytes ${projectPath}/Assets/StreamingAssets/*.txt ${projectPath}/Assets/StreamingAssets/*.plist $allresFiles
90 | zip -r ${workspace}/IOS/res.zip $allresFiles/*
91 | fi
92 |
93 | cd $outpath
94 |
95 | security unlock-keychain -p "123456" ~/Library/Keychains/login.keychain
96 |
97 | xcodebuild clean -project Unity-iPhone.xcodeproj -configuration Release -alltargets
98 |
99 | echo "SignUUID=$SignUUID"
100 | echo "PlistPath=$PlistPath"
101 | echo "CODE_SIGN_IDENTITYStr=$CODE_SIGN_IDENTITYStr"
102 | xcodebuild archive -project Unity-iPhone.xcodeproj -scheme Unity-iPhone platform=iOS -archivePath bin/Unity-iPhone.xcarchive CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITYStr" PROVISIONING_PROFILE="$SignUUID"
103 | echo "打包ipa"
104 | xcodebuild -exportArchive -exportOptionsPlist "$PlistPath" -archivePath bin/Unity-iPhone.xcarchive -exportPath bin/
105 |
106 | if [ -f ${outpath}/bin/Apps/Unity-iPhone.ipa ]; then
107 | cp -f ${outpath}/bin/Apps/Unity-iPhone.ipa $ipaPath
108 | fi
109 |
110 | #fi
111 |
112 |
113 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | ## 使用方法
2 | 修改所有脚本里面的路径为你自己的地址
3 |
4 | ```
5 |
6 | workspace=${workspace}/${BUILD_NUMBER}_${version}
7 |
8 | ```
9 | > 这个东西因为我是用jenkins调用的所以有BUILD_NUMBER和version
10 | > 此处修改成自己要生成的地址就可以
11 |
12 | bash build.sh 参数1名称=参数1值 参数2名称=参数2值 ...
13 |
14 | 之后会调用unity工程里面的 ProjectBuild.cs里面相应函数
15 |
16 | >例如 -executeMethod ProjectBuild.ClearLuaFiles
17 | >那就是调用 ProjectBuild 里面的 ClearLuaFiles方法
18 |
19 | 获取参数值的方法参考ProjectBuild.cs文件
20 |
21 |
22 | ## 目录结构
23 |
24 | - build.sh 总入口
25 | - buildforAndroid.sh 安卓生成的脚本里面有ant打包
26 | - buildforios.sh ios生成的脚本包含生成xcode工程和生成ipa
--------------------------------------------------------------------------------