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
|
#if UNITY_ANDROID
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +16,8 @@ namespace Guru
|
||||||
/// Android混淆器内容填充
|
/// Android混淆器内容填充
|
||||||
/// 于应用构建前执行
|
/// 于应用构建前执行
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UserProguardHelper: IPreprocessBuildWithReport
|
// public class UserProguardHelper: IPreprocessBuildWithReport
|
||||||
|
public class UserProguardHelper
|
||||||
{
|
{
|
||||||
public int callbackOrder { get; } = 0;
|
public int callbackOrder { get; } = 0;
|
||||||
public void OnPreprocessBuild(BuildReport report)
|
public void OnPreprocessBuild(BuildReport report)
|
||||||
|
|
@ -27,7 +31,6 @@ namespace Guru
|
||||||
string proguardPath = $"{Application.dataPath}/Plugins/Android/proguard-user.txt";
|
string proguardPath = $"{Application.dataPath}/Plugins/Android/proguard-user.txt";
|
||||||
if (File.Exists(proguardPath))
|
if (File.Exists(proguardPath))
|
||||||
{
|
{
|
||||||
List<string> keeps = new List<string>();
|
|
||||||
DirectoryInfo dir = new DirectoryInfo(Application.dataPath);
|
DirectoryInfo dir = new DirectoryInfo(Application.dataPath);
|
||||||
string raw = File.ReadAllText(proguardPath);
|
string raw = File.ReadAllText(proguardPath);
|
||||||
|
|
||||||
|
|
@ -41,36 +44,40 @@ namespace Guru
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug.Log($"--- Proguard Files: {files.Length}");
|
// Debug.Log($"--- Proguard Files: {files.Length}");
|
||||||
|
|
||||||
|
ProguardItemBuilder builder = new ProguardItemBuilder();
|
||||||
|
|
||||||
string[] lens = null;
|
var allItems = new List<ProguardItem>(30);
|
||||||
string l = "";
|
|
||||||
|
string[] lines = null;
|
||||||
for (int i = 0; i < files.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
lens = File.ReadAllLines(files[i].FullName);
|
lines = File.ReadAllLines(files[i].FullName);
|
||||||
foreach (var s in lens)
|
var items = builder.BuildItemsFormLines(lines);
|
||||||
{
|
if(items != null && items.Count > 0) allItems.AddRange(items);
|
||||||
l = s.TrimStart();
|
|
||||||
if(string.IsNullOrEmpty(l)) continue;
|
|
||||||
if(raw.Contains(l)) continue;
|
|
||||||
keeps.Add(l);
|
|
||||||
Debug.Log($"--- ✏️ Apply: [ {l} ]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<string> finalLines = new List<string>(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<string> 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")]
|
[MenuItem("Tools/Android/Add proguard-user")]
|
||||||
private static void EditorAddProguardUser()
|
private static void EditorAddProguardUser()
|
||||||
{
|
{
|
||||||
|
|
@ -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
|
#endif
|
||||||
|
|
@ -71,7 +71,7 @@ PluginImporter:
|
||||||
second:
|
second:
|
||||||
enabled: 1
|
enabled: 1
|
||||||
settings:
|
settings:
|
||||||
AddToEmbeddedBinaries: false
|
AddToEmbeddedBinaries: true
|
||||||
CPU: AnyCPU
|
CPU: AnyCPU
|
||||||
CompileFlags:
|
CompileFlags:
|
||||||
FrameworkDependencies:
|
FrameworkDependencies:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue