diff --git a/Editor/GuruBuildSuit/AND_POST_PROGUARD/UserProguardHelper.cs b/Editor/GuruBuildSuit/AND_POST_PROGUARD/UserProguardHelper.cs index 1d5b186..dcefddb 100644 --- a/Editor/GuruBuildSuit/AND_POST_PROGUARD/UserProguardHelper.cs +++ b/Editor/GuruBuildSuit/AND_POST_PROGUARD/UserProguardHelper.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using NUnit.Framework; + #if UNITY_ANDROID namespace Guru { @@ -13,7 +16,8 @@ namespace Guru /// Android混淆器内容填充 /// 于应用构建前执行 /// - public class UserProguardHelper: IPreprocessBuildWithReport + // public class UserProguardHelper: IPreprocessBuildWithReport + public class UserProguardHelper { public int callbackOrder { get; } = 0; public void OnPreprocessBuild(BuildReport report) @@ -27,7 +31,6 @@ namespace Guru string proguardPath = $"{Application.dataPath}/Plugins/Android/proguard-user.txt"; if (File.Exists(proguardPath)) { - List keeps = new List(); DirectoryInfo dir = new DirectoryInfo(Application.dataPath); string raw = File.ReadAllText(proguardPath); @@ -41,36 +44,40 @@ namespace Guru } // Debug.Log($"--- Proguard Files: {files.Length}"); + + ProguardItemBuilder builder = new ProguardItemBuilder(); - string[] lens = null; - string l = ""; + var allItems = new List(30); + + string[] lines = null; for (int i = 0; i < files.Count; i++) { - lens = File.ReadAllLines(files[i].FullName); - foreach (var s in lens) - { - l = s.TrimStart(); - if(string.IsNullOrEmpty(l)) continue; - if(raw.Contains(l)) continue; - keeps.Add(l); - Debug.Log($"--- ✏️ Apply: [ {l} ]"); - } + lines = File.ReadAllLines(files[i].FullName); + var items = builder.BuildItemsFormLines(lines); + if(items != null && items.Count > 0) allItems.AddRange(items); } + + + List finalLines = new List(50); + foreach (var item in allItems) + { + finalLines.AddRange(item.lines); + } + + File.WriteAllLines(proguardPath, finalLines.ToArray()); + Debug.Log($"--- Update proguard-user.txt done! ☀️ ---"); } - - if (keeps.Count == 0) return; // 无注入文件则退出 - - List lines = File.ReadAllLines(proguardPath).ToList(); - lines.Add(""); - lines.AddRange(keeps); - - File.WriteAllLines(proguardPath, lines.ToArray()); - Debug.Log($"--- Update proguard-user.txt done! ☀️ ---"); - } } + + + + + + + [MenuItem("Tools/Android/Add proguard-user")] private static void EditorAddProguardUser() { @@ -78,6 +85,67 @@ namespace Guru } } + + internal class ProguardItemBuilder + { + + + + + + + public List BuildItemsFormLines(string[] lines) + { + List items = new List(30); + + string line = ""; + ProguardItem curItem = null; + + for(int i =0; i < lines.Length; i++) + { + line = lines[i]; + + if(string.IsNullOrEmpty(line)) continue; + + if (curItem == null) + { + curItem = new ProguardItem(); + } + + curItem.Append(line); + + if(line.Contains("}")) + { + items.Add(curItem); + curItem = null; + } + } + + return items; + } + } + + + internal class ProguardItem + { + public List lines = new List(); + public string key = ""; + + public void Append(string line) + { + if (string.IsNullOrEmpty(key) && + line.StartsWith("-")) + { + key = line; + } + + if (lines == null) lines = new List(5); + lines.Add(line); + } + + } + + } #endif \ No newline at end of file diff --git a/Runtime/GuruNetworkMonitor/Plugins/IOS/Connectivity.framework.meta b/Runtime/GuruNetworkMonitor/Plugins/IOS/Connectivity.framework.meta index c082578..f5d2ced 100644 --- a/Runtime/GuruNetworkMonitor/Plugins/IOS/Connectivity.framework.meta +++ b/Runtime/GuruNetworkMonitor/Plugins/IOS/Connectivity.framework.meta @@ -71,7 +71,7 @@ PluginImporter: second: enabled: 1 settings: - AddToEmbeddedBinaries: false + AddToEmbeddedBinaries: true CPU: AnyCPU CompileFlags: FrameworkDependencies: