using System.Diagnostics; using System.IO; using System.Text; using UnityEditor; using UnityEngine; using Debug = UnityEngine.Debug; public class UpLoadBuglySo { private static string[] soFolders = {"arm64-v8a", "armeabi-v7a","unity"}; private static string soCmdAnroid = "java -jar buglyqq-upload-symbol.jar -inputSymbol #SOPATH# -appid #ID# -appkey #KEY# -bundleid #BUNDLEID# -version #VERSION# -platform Android"; private static string soCmdIOS = "java -jar buglyqq-upload-symbol.jar -inputSymbol ./IOS/UnityFramework.framework.dSYM -appid #ID# -appkey #KEY# -bundleid #BUNDLEID# -version #VERSION# -platform IOS"; /// /// 打完包后调用此方法 自动上传符号表文件 /// [MenuItem("Tools/自动上传符号表/Android", priority = 2049)] public static void UploadAndroidBuglyso(){ DeleteSo(); CopyBuglySo(); if (EditCommand(out string arg)) { Debug.Log("EditCommand: " + arg); RunCmd(arg, BuglyToolPath()); } } [MenuItem("Tools/自动上传符号表/IOS", priority = 2049)] public static void UploadIOSBuglyso() { if (EditCommandIOS(out string arg)) { Debug.Log("EditCommand: " + arg); RunCmd(arg, BuglyToolPath()); } } private static void CopyBuglySo(){ FileTool.CopyFolder(DeBugSOPath(), BuglyToolPath() + "/Android/"); FileTool.OpenFolder(BuglyToolPath()); } private static void DeleteSo(){ foreach (var folder in soFolders) { FileTool.DeleteFolder(BuglyToolPath() + "/Android/"); } } private static bool EditCommand(out string arg){ bool exists = false; var versionInfo = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", VersionConfig.Get().buildTime); StringBuilder sb = new StringBuilder(); foreach (var folder in soFolders) { exists = true; sb.Append(soCmdAnroid).Append(" & "); if(folder == "unity") { sb.Replace("#SOPATH#", "libunity.sym.so"); } else { string soPath = BuglyToolPath() + "/Android/" + folder ; if (FileTool.CheckFolder(soPath)) { soPath = soPath + "/libil2cpp.sym.so"; sb.Replace("#SOPATH#", soPath); } else { exists = false; break; } } sb.Replace("#ID#", ExceptionCatcher.AppIDAndroid); //这里注意一下要改成自己的id sb.Replace("#KEY#", ExceptionCatcher.AppKeyAndroid); //自己的key sb.Replace("#BUNDLEID#", VersionConfig.Get().appId); sb.Replace("#VERSION#", versionInfo); } sb.Append("exit").Replace("/", @"\"); arg = sb.ToString(); return exists; } private static bool EditCommandIOS(out string arg) { bool exists = true; var versionInfo = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", VersionConfig.Get().buildTime); StringBuilder sb = new StringBuilder(); sb.Append(soCmdIOS).Append(" & "); sb.Replace("#ID#", ExceptionCatcher.AppIDIOS); //这里注意一下要改成自己的id sb.Replace("#KEY#", ExceptionCatcher.AppKeyIOS); //自己的key sb.Replace("#BUNDLEID#", VersionConfig.Get().appId); sb.Replace("#VERSION#", versionInfo); sb.Append("exit").Replace("/", @"\"); arg = sb.ToString(); return exists; } public static string DeBugSOPath(){ return Path.GetFullPath(Application.dataPath + "/../Temp/StagingArea/symbols"); } public static string BuglyToolPath(){ return Path.GetFullPath(Application.dataPath + "/../buglytools"); } public static void RunCmd(string arg, string workingDirectory,string exe ="cmd.exe"){ ProcessStartInfo info = new ProcessStartInfo(exe); info.Arguments = "/c " + arg; info.WorkingDirectory = workingDirectory; info.CreateNoWindow = false; info.ErrorDialog = true; info.UseShellExecute = true; if (info.UseShellExecute) { info.RedirectStandardOutput = false; info.RedirectStandardError = false; info.RedirectStandardInput = false; } else { info.RedirectStandardOutput = true; info.RedirectStandardError = true; info.RedirectStandardInput = true; info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8; info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8; } Debug.Log("RunCmd: "+info.Arguments); Process process = Process.Start(info); if (!info.UseShellExecute) { Debug.Log(process.StandardOutput); Debug.Log(process.StandardError); } process.WaitForExit(); process.Close(); } }