static void Process_DevCinfig_Auto_GEN(int ddownload, string server, string version, string engine_version) { //DownloadSources ss = (DownloadSources)(ddownload); string script = "public partial class DevConfig\n{\n"; Patches.Version v = new Patches.Version(); v.Parse(engine_version); script += " public static int __ENGINE_VERSION__ = " + (v.MainVersion * 100000 + v.SubVersion) + ";\n}"; File.WriteAllText("Assets/DevConfig_Auto_GEN.cs", script); File.WriteAllText("Assets/Resources/__DOWNLOAD_SOURCES__.txt", ddownload.ToString()); File.WriteAllText("Assets/Resources/__SERVER_TYPE__.txt", ((int)((ServerPlatform)Enum.Parse(typeof(ServerPlatform), server))).ToString()); File.WriteAllText("Assets/Resources/__VERSION__.txt", version); AssetDatabase.Refresh(); }
public static void _BuildZip_Android() { string path_pre_name = "VersionFiles/AssetBundles/Android/"; string path = EditorUtils.Utils.GetCurrentWorkingPath() + "/VersionFiles/AssetBundles/Android/AssetBundles_diff"; //需要构建的版本号 string v = File.ReadAllText("VersionFiles/VERSION.txt"); string out_zip_full_name = "android_" + v + ".zip"; // "VersionFiles/" + v + "/android_" + v + ".zip"; using (ZipFile zip = ZipFile.Create(out_zip_full_name)) { zip.BeginUpdate(); zip.AddDirectory("AssetBundles"); try { Directory.Delete("AssetBundles_diff", true); } catch (Exception e) { } //这样绕一下处理diff是因为 lua/lua这个文件 在 原路径下 打包zip会出错(ziplib的BUG) EditorUtils.Utils.CopyDir("VersionFiles/AssetBundles/Android/AssetBundles_diff", "AssetBundles_diff"); foreach (var d in Directory.GetDirectories("AssetBundles_diff")) { zip.AddDirectory(d.Replace("AssetBundles_diff", "AssetBundles")); } foreach (var p in Directory.GetFiles("AssetBundles_diff", "*", SearchOption.AllDirectories)) { zip.Add(p, p.Replace("AssetBundles_diff", "AssetBundles")); } zip.CommitUpdate(); Directory.Delete("AssetBundles_diff", true); } if (File.Exists("VersionFiles/" + v + "/android_" + v + ".zip")) { File.Delete("VersionFiles/" + v + "/android_" + v + ".zip"); } if (Directory.Exists("VersionFiles/" + v) == false) { Directory.CreateDirectory("VersionFiles/" + v); } File.Move(out_zip_full_name, "VersionFiles/" + v + "/android_" + v + ".zip"); File.Delete(out_zip_full_name); out_zip_full_name = "VersionFiles/" + v + "/android_" + v + ".zip"; string md5 = MD5Code.GetMD5HashFromFile(out_zip_full_name); int size = 0; using (var zip = File.OpenRead(out_zip_full_name)) { size = (int)zip.Length; } Patches.Version this_version = new Patches.Version(); Debug.Log("Patch Zip:will build version = " + v); this_version.Parse(v); this_version.MD5 = md5; this_version.FileSize = size; // Debug.LogError(LitJson.JsonMapper.ToJson(this_version)); { var ss = File.CreateText("VersionFiles/" + v + "/android_" + v + ".json"); ss.Write(LitJson.JsonMapper.ToJson(this_version)); ss.Flush(); ss.Close(); } //resfresh all { // Debug.LogError(pat); var patches = Directory.GetDirectories("VersionFiles", this_version.MainVersion + ".*.*", SearchOption.AllDirectories); List <Patches.Version> _patch_vs = new System.Collections.Generic.List <Patches.Version>(); foreach (var pp in patches) { var p = Path.GetFileName(pp); Patches.Version vv = new Patches.Version(); vv.Parse(p); _patch_vs.Add(vv); } _patch_vs.Sort(); VersionList _VL = new VersionList(); foreach (var p in _patch_vs) { string ver = p.MainVersion.ToString() + "." + p.SubVersion.ToString() + "." + p.PatchVersion.ToString() + "/android_" + p.MainVersion.ToString() + "." + p.SubVersion.ToString() + "." + p.PatchVersion.ToString() + ".json"; var this_v = File.ReadAllText("VersionFiles/" + ver); Debug.LogError(ver); _VL.versions.Add(LitJson.JsonMapper.ToObject <Patches.Version>(this_v)); } { var ss = File.CreateText("VersionFiles/FULL_VERSIONS.json"); ss.Write(LitJson.JsonMapper.ToJson(_VL)); ss.Flush(); ss.Close(); } } Debug.Log("Patch Zip:build android done "); }
public static void _BuildZip() { //需要构建的版本号 string v = File.ReadAllText("VersionFiles/VERSION.txt"); string out_zip_full_name = "android_" + v + ".zip"; // "VersionFiles/" + v + "/android_" + v + ".zip"; using (ZipFile zip = ZipFile.Create(out_zip_full_name)) { zip.BeginUpdate(); zip.AddDirectory("AssetBundles"); foreach (var d in Directory.GetDirectories("AssetBundles")) { zip.AddDirectory(d); } foreach (var p in Directory.GetFiles("AssetBundles", "*", SearchOption.AllDirectories)) { zip.Add(p); // Debug.LogError(p); } zip.CommitUpdate(); } if (File.Exists("VersionFiles/" + v + "/android_" + v + ".zip")) { File.Delete("VersionFiles/" + v + "/android_" + v + ".zip"); } if (Directory.Exists("VersionFiles/" + v) == false) { Directory.CreateDirectory("VersionFiles/" + v); } File.Move(out_zip_full_name, "VersionFiles/" + v + "/android_" + v + ".zip"); File.Delete(out_zip_full_name); out_zip_full_name = "VersionFiles/" + v + "/android_" + v + ".zip"; string md5 = MD5Code.GetMD5HashFromFile(out_zip_full_name); int size = 0; using (var zip = File.OpenRead(out_zip_full_name)) { size = (int)zip.Length; } Patches.Version this_version = new Patches.Version(); Debug.LogError(v); this_version.Parse(v); this_version.MD5 = md5; this_version.FileSize = size; Debug.LogError(LitJson.JsonMapper.ToJson(this_version)); { var ss = File.CreateText("VersionFiles/" + v + "/android_" + v + ".json"); ss.Write(LitJson.JsonMapper.ToJson(this_version)); ss.Flush(); ss.Close(); } //resfresh all { string pat = this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + "."; // Debug.LogError(pat); var patches = Directory.GetDirectories("VersionFiles", this_version.MainVersion + "." + this_version.SubVersion + ".*", SearchOption.AllDirectories); List <int> _patch_vs = new System.Collections.Generic.List <int>(); foreach (var pp in patches) { var p = Path.GetFileName(pp); Patches.Version vv = new Patches.Version(); Debug.LogError(pp + " " + p); vv.Parse(p); _patch_vs.Add(vv.PatchVersion); } _patch_vs.Sort(); VersionList _VL = new VersionList(); foreach (var p in _patch_vs) { string ver = this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + "." + p.ToString() + "/android_" + this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + "." + p.ToString() + ".json"; var this_v = File.ReadAllText("VersionFiles/" + ver); Debug.LogError(ver); Patches.Version x = new Patches.Version(); _VL.versions.Add(LitJson.JsonMapper.ToObject <Patches.Version>(this_v)); } { var ss = File.CreateText("VersionFiles/FULL_VERSIONS.json"); ss.Write(LitJson.JsonMapper.ToJson(_VL)); ss.Flush(); ss.Close(); } } }
public static void BuildApk(string APK_ROOT, ScriptingImplementation scriptBackend, bool isDevelop = false) { try { try { if (Directory.Exists(APK_ROOT)) { Directory.Delete(APK_ROOT, true); } if (!Directory.Exists(APK_ROOT)) { Directory.CreateDirectory(APK_ROOT); } } catch (Exception e) { } BuildAndriodTasks tasks = JsonUtility.FromJson <BuildAndriodTasks>(File.ReadAllText(ROOT_DIR + "/build_android_task.json")); BuildAndriodCommon common = tasks.common; //设置 打包的场景 foreach (var task in tasks.tasks) { Thread.Sleep(1000); //sync AssetDatabase.Refresh(ImportAssetOptions.Default); List <string> _scenes = new System.Collections.Generic.List <string>(); foreach (var sc in EditorBuildSettings.scenes) { if (sc.enabled == false) { continue; } _scenes.Add(sc.path); } //设置apk 包体信息 if (task.devconfig_download_sources == 10) { // 百度 PlayerSettings.SplashScreen.show = false; } else { PlayerSettings.SplashScreen.show = true; } Patches.Version v = new Patches.Version(); v.Parse(common.__ENGINE_VERSION__); PlayerSettings.Android.bundleVersionCode = common.bundle_version_code; PlayerSettings.bundleVersion = string.Format("{0}.{1}.{2}", v.MainVersion, v.SubVersion, task.devconfig_download_sources); PlayerSettings.applicationIdentifier = task.package_name; PlayerSettings.Android.minSdkVersion = (AndroidSdkVersions)common.minSdkVersion; //修正 target SDK version 的值 // if (common.devconfig_server_platform == "ServerRelease") // { // PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel23; // } // else // { // PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel25; // } Process_DevCinfig_Auto_GEN(task.devconfig_download_sources, common.devconfig_server_platform, common.__Version__, common.__ENGINE_VERSION__); Process_AD_SDK(task); Process_PUSH_SDK(task); Process_LebianClientChId(task); PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, scriptBackend); string file = APK_ROOT + "/" + common.output_name_pre + common.version + "." + task.devconfig_download_sources + ".apk"; try { File.Delete(file); } catch (Exception e) { } //sync AssetDatabase.Refresh(ImportAssetOptions.Default); /*UnityEditor.Build.Reporting.BuildReport error = */ if (isDevelop) { BuildPipeline.BuildPlayer(_scenes.ToArray(), file, BuildTarget.Android, BuildOptions.Development | BuildOptions.ConnectWithProfiler); } else { BuildPipeline.BuildPlayer(_scenes.ToArray(), file, BuildTarget.Android, BuildOptions.None); } /* if (error.) * { * Debug.LogError("build faild " + error); * return; * }*/ Debug.Log("build " + file + " ok"); } } catch (Exception e) { Debug.LogError("build faild " + e.Message); } }