update:ChannelConfig 更新
This commit is contained in:
@@ -8,7 +8,7 @@ using UnityEngine;
|
||||
|
||||
public class ChannelBuildTool
|
||||
{
|
||||
private const string ExtraCfgRoot = "../ExtraPluginCfgs/Android";
|
||||
private const string ChannelConfigRoot = "../ChannelConfigs/Android";
|
||||
private const string TysdkPlugins = "Packages/tysdk/Plugins/Android";
|
||||
private const string TysdkFiles = "Packages/tysdk/Files";
|
||||
private const string AssetsPlugins = "Assets/Plugins/Android";
|
||||
@@ -18,6 +18,8 @@ public class ChannelBuildTool
|
||||
private const string DefaultProductName = "Fishing Travel";
|
||||
private const string EnjoyPayProductName = "Fishing Travel: Hook & Explore";
|
||||
private const string ChannelManifestLib = "channel_manifest_lib";
|
||||
private const string ChannelGradle = "channel_gradle";
|
||||
private const string ChannelMetaName = "com.arkgame.ft.channel";
|
||||
private const string EmptyManifest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" />\n";
|
||||
private static readonly XNamespace AndroidNamespace = "http://schemas.android.com/apk/res/android";
|
||||
private static readonly XNamespace ToolsNamespace = "http://schemas.android.com/tools";
|
||||
@@ -27,11 +29,7 @@ public class ChannelBuildTool
|
||||
public static void SwitchChannel(string channel)
|
||||
{
|
||||
channel = NormalizeChannelName(channel);
|
||||
var cfgDir = Path.Combine(ExtraCfgRoot, channel.ToLowerInvariant());
|
||||
if (!Directory.Exists(cfgDir))
|
||||
{
|
||||
throw new DirectoryNotFoundException($"[ChannelSwitch] Channel config not found: {cfgDir}");
|
||||
}
|
||||
var cfgDir = Path.Combine(ChannelConfigRoot, channel.ToLowerInvariant());
|
||||
|
||||
Debug.Log($"[ChannelSwitch] Switching to {channel}...");
|
||||
CleanChannelManifestLibBuildArtifacts();
|
||||
@@ -43,41 +41,13 @@ public class ChannelBuildTool
|
||||
SyncChannelAdapterFiles(cfgDir);
|
||||
|
||||
// 3. Sync google-services.json
|
||||
var srcGoogleServices = Path.Combine(cfgDir, "Files/google-services.json");
|
||||
if (File.Exists(srcGoogleServices))
|
||||
{
|
||||
var destDir = Path.Combine(TysdkFiles);
|
||||
if (!Directory.Exists(destDir)) Directory.CreateDirectory(destDir);
|
||||
var destGoogleServices = Path.Combine(destDir, "google-services.json");
|
||||
File.Copy(srcGoogleServices, destGoogleServices, true);
|
||||
Debug.Log($"[ChannelSwitch] google-services.json -> {destGoogleServices}");
|
||||
}
|
||||
SyncGoogleServices(cfgDir);
|
||||
|
||||
// 4. Sync channel plugin files (.aar, .jar, etc.) to tysdk package
|
||||
var pluginsSrcDir = Path.Combine(cfgDir, "Plugins/Android");
|
||||
var pluginsDestDir = TysdkPlugins;
|
||||
if (Directory.Exists(pluginsSrcDir))
|
||||
{
|
||||
foreach (var oldPlugin in Directory.GetFiles(pluginsDestDir, "tuyoosdk_*.aar"))
|
||||
File.Delete(oldPlugin);
|
||||
|
||||
foreach (var pluginFile in Directory.GetFiles(pluginsSrcDir))
|
||||
{
|
||||
if (pluginFile.EndsWith(".meta")) continue;
|
||||
var fileName = Path.GetFileName(pluginFile);
|
||||
var dest = Path.Combine(pluginsDestDir, fileName);
|
||||
File.Copy(pluginFile, dest, true);
|
||||
Debug.Log($"[ChannelSwitch] Plugin: {pluginFile} -> {dest}");
|
||||
}
|
||||
}
|
||||
SyncChannelPluginFiles(cfgDir);
|
||||
|
||||
// 5. Set Bundle Identifier per channel
|
||||
var bundleId = channel switch
|
||||
{
|
||||
"Flexion" => "com.arkgame.ft.flexion",
|
||||
"EnjoyPay" => "com.arkgame.ft.ep",
|
||||
_ => "com.arkgame.ft"
|
||||
};
|
||||
var bundleId = GetBundleId(channel);
|
||||
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, bundleId);
|
||||
Debug.Log($"[ChannelSwitch] Bundle Identifier -> {bundleId}");
|
||||
|
||||
@@ -99,16 +69,22 @@ public class ChannelBuildTool
|
||||
// ==================== Menu ====================
|
||||
|
||||
[MenuItem("Tools/Channel/Switch Channel/GooglePlay", false, 10000)]
|
||||
public static void Switch_GooglePlay() => SwitchChannel("GooglePlay");
|
||||
public static void Switch_GooglePlay() => SwitchChannelTo("GooglePlay");
|
||||
|
||||
[MenuItem("Tools/Channel/Switch Channel/Flexion", false, 10001)]
|
||||
public static void Switch_Flexion() => SwitchChannel("Flexion");
|
||||
public static void Switch_Flexion() => SwitchChannelTo("Flexion");
|
||||
|
||||
[MenuItem("Tools/Channel/Switch Channel/Rustore", false, 10002)]
|
||||
public static void Switch_Rustore() => SwitchChannel("Rustore");
|
||||
public static void Switch_Rustore() => SwitchChannelTo("Rustore");
|
||||
|
||||
[MenuItem("Tools/Channel/Switch Channel/EnjoyPay", false, 10003)]
|
||||
public static void Switch_EnjoyPay() => SwitchChannel("EnjoyPay");
|
||||
public static void Switch_EnjoyPay() => SwitchChannelTo("EnjoyPay");
|
||||
|
||||
private static void SwitchChannelTo(string channel)
|
||||
{
|
||||
RestoreChannelWorkspace(skipOnCi: true);
|
||||
SwitchChannel(channel);
|
||||
}
|
||||
|
||||
// ==================== Build ====================
|
||||
|
||||
@@ -116,6 +92,7 @@ public class ChannelBuildTool
|
||||
{
|
||||
try
|
||||
{
|
||||
RestoreChannelWorkspace(skipOnCi: true);
|
||||
CleanChannelManifestLibBuildArtifacts();
|
||||
SwitchChannel(channel);
|
||||
|
||||
@@ -148,7 +125,7 @@ public class ChannelBuildTool
|
||||
}
|
||||
finally
|
||||
{
|
||||
SwitchChannel("GooglePlay");
|
||||
RestoreChannelWorkspace(skipOnCi: true);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
@@ -177,6 +154,12 @@ public class ChannelBuildTool
|
||||
[MenuItem("Tools/Channel/Build Android (Channel)/EnjoyPay Debug", false, 10107)]
|
||||
public static void Build_EnjoyPay_Debug() => BuildAndroidForChannel("EnjoyPay", true);
|
||||
|
||||
[MenuItem("Tools/Channel/Restore Workspace (Git Checkout)", false, 10200)]
|
||||
public static void RestoreChannelWorkspaceWithGitCheckoutMenu()
|
||||
{
|
||||
RestoreChannelWorkspace(skipOnCi: false);
|
||||
}
|
||||
|
||||
private static string NormalizeChannelName(string channel)
|
||||
{
|
||||
if (string.IsNullOrEmpty(channel))
|
||||
@@ -197,10 +180,65 @@ public class ChannelBuildTool
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetBundleId(string channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
"Flexion" => "com.arkgame.ft.flexion",
|
||||
"EnjoyPay" => "com.arkgame.ft.ep",
|
||||
_ => "com.arkgame.ft"
|
||||
};
|
||||
}
|
||||
|
||||
private static void RestoreChannelWorkspace(bool skipOnCi)
|
||||
{
|
||||
if (skipOnCi && IsCiBuild())
|
||||
{
|
||||
Debug.Log("[ChannelSwitch] Skip git checkout restore on CI.");
|
||||
return;
|
||||
}
|
||||
|
||||
RunCommand("git", "checkout -- .");
|
||||
RunCommand("git", "clean -fd -- .");
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
|
||||
Debug.Log("[ChannelSwitch] Workspace restored from git index.");
|
||||
}
|
||||
|
||||
private static bool IsCiBuild()
|
||||
{
|
||||
return !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("JENKINS_URL")) ||
|
||||
!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("JENKINS_HOME")) ||
|
||||
!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("BUILD_NUMBER"));
|
||||
}
|
||||
|
||||
private static void RunCommand(string fileName, string arguments)
|
||||
{
|
||||
var startInfo = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = arguments,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (var process = System.Diagnostics.Process.Start(startInfo))
|
||||
{
|
||||
var output = process.StandardOutput.ReadToEnd();
|
||||
var error = process.StandardError.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
throw new System.InvalidOperationException($"{fileName} {arguments} failed.\n{output}\n{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SyncRootAndroidConfigFiles(string channel, string cfgDir)
|
||||
{
|
||||
CopyRootConfigFiles(cfgDir, "*.gradle");
|
||||
CopyRootConfigFiles(cfgDir, "*.properties");
|
||||
SyncChannelGradleFiles(channel, cfgDir);
|
||||
SetMainManifestChannel(channel);
|
||||
SyncChannelManifestLib(channel, cfgDir);
|
||||
}
|
||||
@@ -214,6 +252,11 @@ public class ChannelBuildTool
|
||||
File.Delete(oldJava);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(cfgDir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var javaFile in Directory.GetFiles(cfgDir, "*Adapter.java"))
|
||||
{
|
||||
var fileName = Path.GetFileName(javaFile);
|
||||
@@ -223,10 +266,50 @@ public class ChannelBuildTool
|
||||
}
|
||||
}
|
||||
|
||||
private static void SyncGoogleServices(string cfgDir)
|
||||
{
|
||||
var dest = Path.Combine(TysdkFiles, "google-services.json");
|
||||
var src = Path.Combine(cfgDir, "Files", "google-services.json");
|
||||
if (!File.Exists(src))
|
||||
{
|
||||
Debug.Log($"[ChannelSwitch] google-services.json not copied. Checked={src}");
|
||||
return;
|
||||
}
|
||||
|
||||
var destDir = Path.GetDirectoryName(dest);
|
||||
if (!Directory.Exists(destDir)) Directory.CreateDirectory(destDir);
|
||||
File.Copy(src, dest, true);
|
||||
Debug.Log($"[ChannelSwitch] google-services.json -> {dest}");
|
||||
}
|
||||
|
||||
private static void SyncChannelPluginFiles(string cfgDir)
|
||||
{
|
||||
var pluginsSrcDir = Path.Combine(cfgDir, "Plugins", "Android");
|
||||
if (!Directory.Exists(pluginsSrcDir))
|
||||
{
|
||||
Debug.Log($"[ChannelSwitch] Plugin directory not found. Checked={pluginsSrcDir}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var oldPlugin in Directory.GetFiles(TysdkPlugins, "tuyoosdk_*.aar"))
|
||||
{
|
||||
File.Delete(oldPlugin);
|
||||
}
|
||||
|
||||
foreach (var pluginFile in Directory.GetFiles(pluginsSrcDir))
|
||||
{
|
||||
if (pluginFile.EndsWith(".meta")) continue;
|
||||
var fileName = Path.GetFileName(pluginFile);
|
||||
var dest = Path.Combine(TysdkPlugins, fileName);
|
||||
File.Copy(pluginFile, dest, true);
|
||||
Debug.Log($"[ChannelSwitch] Plugin: {pluginFile} -> {dest}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void SyncChannelManifestLib(string channel, string cfgDir)
|
||||
{
|
||||
var dest = Path.Combine(AssetsPlugins, ChannelManifestLib, "src");
|
||||
if (channel == "GooglePlay")
|
||||
if (channel == "GooglePlay" || !Directory.Exists(cfgDir))
|
||||
{
|
||||
WriteEmptyChannelManifestLib(dest);
|
||||
Debug.Log($"[ChannelSwitch] Manifest lib reset to empty default. Channel={channel}");
|
||||
@@ -243,6 +326,31 @@ public class ChannelBuildTool
|
||||
Debug.Log($"[ChannelSwitch] Manifest: {srcManifest} -> {Path.Combine(dest, "main", "AndroidManifest.xml")}");
|
||||
}
|
||||
|
||||
private static void SyncChannelGradleFiles(string channel, string cfgDir)
|
||||
{
|
||||
var src = Path.Combine(cfgDir, "Plugins", "Android", "gradle");
|
||||
var dest = Path.Combine(AssetsPlugins, ChannelGradle);
|
||||
if (Directory.Exists(dest))
|
||||
{
|
||||
Directory.Delete(dest, true);
|
||||
}
|
||||
|
||||
var destMeta = dest + ".meta";
|
||||
if (File.Exists(destMeta))
|
||||
{
|
||||
File.Delete(destMeta);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(src))
|
||||
{
|
||||
Debug.Log($"[ChannelSwitch] Gradle increment reset to empty default. Channel={channel}");
|
||||
return;
|
||||
}
|
||||
|
||||
CopyDirectoryClean(src, dest);
|
||||
Debug.Log($"[ChannelSwitch] Gradle increment: {src} -> {dest}");
|
||||
}
|
||||
|
||||
private static void SetMainManifestChannel(string channel)
|
||||
{
|
||||
var manifestPath = Path.Combine(AssetsPlugins, "AndroidManifest.xml");
|
||||
@@ -259,23 +367,31 @@ public class ChannelBuildTool
|
||||
throw new InvalidDataException($"[ChannelSwitch] Main AndroidManifest application node not found: {manifestPath}");
|
||||
}
|
||||
|
||||
var channelMeta = application.Elements()
|
||||
.FirstOrDefault(x => x.Name.LocalName == "meta-data" &&
|
||||
(string)x.Attribute(AndroidNamespace + "name") == "com.arkgame.ft.channel");
|
||||
if (channelMeta == null)
|
||||
{
|
||||
channelMeta = new XElement("meta-data",
|
||||
new XAttribute(AndroidNamespace + "name", "com.arkgame.ft.channel"));
|
||||
application.Add(channelMeta);
|
||||
}
|
||||
|
||||
channelMeta.SetAttributeValue(AndroidNamespace + "value", channel);
|
||||
root.SetAttributeValue("package", GetBundleId(channel));
|
||||
SetMainManifestChannelMeta(application, channel);
|
||||
SetMainManifestBackupRules(application, channel);
|
||||
doc.Save(manifestPath);
|
||||
AssetDatabase.ImportAsset(manifestPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate);
|
||||
Debug.Log($"[ChannelSwitch] Main manifest channel -> {channel}");
|
||||
}
|
||||
|
||||
private static void SetMainManifestChannelMeta(XElement application, string channel)
|
||||
{
|
||||
var channelMeta = application.Elements()
|
||||
.FirstOrDefault(x => x.Name.LocalName == "meta-data" &&
|
||||
(string)x.Attribute(AndroidNamespace + "name") == ChannelMetaName);
|
||||
|
||||
if (channelMeta == null)
|
||||
{
|
||||
channelMeta = new XElement("meta-data",
|
||||
new XAttribute(AndroidNamespace + "name", ChannelMetaName));
|
||||
application.Add(channelMeta);
|
||||
}
|
||||
|
||||
channelMeta.SetAttributeValue(AndroidNamespace + "name", ChannelMetaName);
|
||||
channelMeta.SetAttributeValue(AndroidNamespace + "value", channel);
|
||||
}
|
||||
|
||||
private static void SetMainManifestBackupRules(XElement application, string channel)
|
||||
{
|
||||
const string fullBackupContent = "android:fullBackupContent";
|
||||
@@ -348,22 +464,6 @@ public class ChannelBuildTool
|
||||
}
|
||||
}
|
||||
|
||||
private static void CopyRootConfigFiles(string cfgDir, string searchPattern)
|
||||
{
|
||||
foreach (var src in Directory.GetFiles(cfgDir, searchPattern, SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
CopyRootConfigFile(src);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CopyRootConfigFile(string src)
|
||||
{
|
||||
var fileName = Path.GetFileName(src);
|
||||
var dest = Path.Combine(AssetsPlugins, fileName);
|
||||
File.Copy(src, dest, true);
|
||||
Debug.Log($"[ChannelSwitch] Config: {src} -> {dest}");
|
||||
}
|
||||
|
||||
private static void CopyDirectoryClean(string src, string dest)
|
||||
{
|
||||
if (Directory.Exists(dest))
|
||||
@@ -414,11 +514,12 @@ public class ChannelBuildTool
|
||||
if (!File.Exists(src) && UsesRustoreAddressablesContentState(channel))
|
||||
{
|
||||
Debug.Log($"[ChannelSwitch] Channel content state not found, try legacy Rustore content state path. Channel={channel}, checked={src}");
|
||||
src = Path.Combine("../ExtraPluginCfgs", AddressablesContentState);
|
||||
src = Path.Combine("../ChannelConfigs", AddressablesContentState);
|
||||
}
|
||||
|
||||
if (!File.Exists(src))
|
||||
{
|
||||
ClearAddressablesContentState(channel);
|
||||
Debug.Log($"[ChannelSwitch] Addressables content state not copied. Channel={channel}, checked={src}");
|
||||
return;
|
||||
}
|
||||
@@ -430,6 +531,34 @@ public class ChannelBuildTool
|
||||
Debug.Log($"[ChannelSwitch] Addressables content state: {src} -> {AndroidAddressablesContentState}");
|
||||
}
|
||||
|
||||
private static void ClearAddressablesContentState(string channel)
|
||||
{
|
||||
if (File.Exists(AndroidAddressablesContentState))
|
||||
{
|
||||
File.Delete(AndroidAddressablesContentState);
|
||||
}
|
||||
|
||||
var meta = AndroidAddressablesContentState + ".meta";
|
||||
if (File.Exists(meta))
|
||||
{
|
||||
File.Delete(meta);
|
||||
}
|
||||
|
||||
var dir = Path.GetDirectoryName(AndroidAddressablesContentState);
|
||||
if (Directory.Exists(dir) && !Directory.EnumerateFileSystemEntries(dir).Any())
|
||||
{
|
||||
Directory.Delete(dir);
|
||||
}
|
||||
|
||||
var dirMeta = dir + ".meta";
|
||||
if (File.Exists(dirMeta) && !Directory.Exists(dir))
|
||||
{
|
||||
File.Delete(dirMeta);
|
||||
}
|
||||
|
||||
Debug.Log($"[ChannelSwitch] Addressables content state cleared. Channel={channel}");
|
||||
}
|
||||
|
||||
private static bool UsesRustoreAddressablesContentState(string channel)
|
||||
{
|
||||
return channel == "Rustore" || channel == "EnjoyPay";
|
||||
|
||||
Reference in New Issue
Block a user