update: 暂时移除 UserProguard 修复器
--story=1020956 --user=yufei.hu 【中台】【Android】构建插件 API 升级 34 验证 https://www.tapd.cn/33527076/s/1160300 Signed-off-by: huyufei <yufei.hu@castbox.fm>dev
parent
15aa840061
commit
88d29fe2f2
|
|
@ -1,3 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
namespace Guru
|
||||
{
|
||||
|
|
@ -13,7 +16,8 @@ namespace Guru
|
|||
/// Android混淆器内容填充
|
||||
/// 于应用构建前执行
|
||||
/// </summary>
|
||||
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<string> keeps = new List<string>();
|
||||
DirectoryInfo dir = new DirectoryInfo(Application.dataPath);
|
||||
string raw = File.ReadAllText(proguardPath);
|
||||
|
||||
|
|
@ -42,33 +45,37 @@ namespace Guru
|
|||
|
||||
// Debug.Log($"--- Proguard Files: {files.Length}");
|
||||
|
||||
string[] lens = null;
|
||||
string l = "";
|
||||
ProguardItemBuilder builder = new ProguardItemBuilder();
|
||||
|
||||
var allItems = new List<ProguardItem>(30);
|
||||
|
||||
string[] lines = null;
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
lens = File.ReadAllLines(files[i].FullName);
|
||||
foreach (var s in lens)
|
||||
lines = File.ReadAllLines(files[i].FullName);
|
||||
var items = builder.BuildItemsFormLines(lines);
|
||||
if(items != null && items.Count > 0) allItems.AddRange(items);
|
||||
}
|
||||
|
||||
|
||||
List<string> finalLines = new List<string>(50);
|
||||
foreach (var item in allItems)
|
||||
{
|
||||
l = s.TrimStart();
|
||||
if(string.IsNullOrEmpty(l)) continue;
|
||||
if(raw.Contains(l)) continue;
|
||||
keeps.Add(l);
|
||||
Debug.Log($"--- ✏️ Apply: [ {l} ]");
|
||||
}
|
||||
}
|
||||
finalLines.AddRange(item.lines);
|
||||
}
|
||||
|
||||
if (keeps.Count == 0) return; // 无注入文件则退出
|
||||
|
||||
List<string> lines = File.ReadAllLines(proguardPath).ToList();
|
||||
lines.Add("");
|
||||
lines.AddRange(keeps);
|
||||
|
||||
File.WriteAllLines(proguardPath, lines.ToArray());
|
||||
File.WriteAllLines(proguardPath, finalLines.ToArray());
|
||||
Debug.Log($"--- Update proguard-user.txt done! ☀️ ---");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Tools/Android/Add proguard-user")]
|
||||
|
|
@ -78,6 +85,67 @@ namespace Guru
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
internal class ProguardItemBuilder
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<ProguardItem> BuildItemsFormLines(string[] lines)
|
||||
{
|
||||
List<ProguardItem> items = new List<ProguardItem>(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<string> lines = new List<string>();
|
||||
public string key = "";
|
||||
|
||||
public void Append(string line)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) &&
|
||||
line.StartsWith("-"))
|
||||
{
|
||||
key = line;
|
||||
}
|
||||
|
||||
if (lines == null) lines = new List<string>(5);
|
||||
lines.Add(line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -71,7 +71,7 @@ PluginImporter:
|
|||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
AddToEmbeddedBinaries: true
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
|
|
|
|||
Loading…
Reference in New Issue