三国卡牌客户端基础资源仓库
yyl
2026-05-15 0229e944a9f77b8622ae2b34ef0fa314a8aa0fc2
Assets/Editor/Tool/ClientPackage.cs
@@ -316,8 +316,8 @@
        File.Copy(copySdkFile, File_baseProjectTemplate);
        copySdkFile = StringUtility.Concat(_sdkPath, "/Channel/Android/", versionConfig.sdkFileName, "/deps.gradle");
        File.Copy(copySdkFile, File_deps);
        copySdkFile = StringUtility.Concat(_sdkPath, "/Channel/Android/", versionConfig.sdkFileName, "/google-services.json");
        File.Copy(copySdkFile, File_google_services);
        // copySdkFile = StringUtility.Concat(_sdkPath, "/Channel/Android/", versionConfig.sdkFileName, "/google-services.json");
        // File.Copy(copySdkFile, File_google_services);
        copySdkFile = StringUtility.Concat(_sdkPath, "/Channel/Android/", versionConfig.sdkFileName, "/gradleTemplate.properties");
        File.Copy(copySdkFile, File_gradleTemplate);
        copySdkFile = StringUtility.Concat(_sdkPath, "/Channel/Android/", versionConfig.sdkFileName, "/LauncherManifest.xml");
@@ -399,40 +399,47 @@
            return;
        }
        PreBuild(_publisher, _buildIndex);
        var versionName = string.Empty;
        var versionConfig = GetVersionConfig(_publisher, out versionName);
        // 导出前清理 Assets/Plugins/Android(保留 libs 目录)
        CleanupPluginsAndroidForExport();
        string copySdkFile;
        copySdkFile = StringUtility.Concat(SDK_PLUGIN_PROJECT, "/Channel/Android/", versionConfig.sdkFileName, "/AndroidManifest.xml");
        File.Copy(copySdkFile, MANIFEST_PATH);
        PreBuild(_publisher, _buildIndex);
        PlayerSettings.Android.bundleVersionCode = VersionConfig.GetVersionNumber(versionConfig.version);
        PlayerSettings.enableInternalProfiler = _development;
        // 先清理StreamingAssets,再根据assetAccess配置拷贝资源到StreamingAssets
        var streamingPath = ResourcesPath.Instance.StreamingAssetPath;
        if (Directory.Exists(streamingPath))
            Directory.Delete(streamingPath, true);
        //完整取StreamingAssets 资源
        // // 先清理StreamingAssets,再根据assetAccess配置拷贝资源到StreamingAssets
        // var streamingPath = ResourcesPath.Instance.StreamingAssetPath;
        // if (Directory.Exists(streamingPath))
        //     Directory.Delete(streamingPath, true);
        if (!string.IsNullOrEmpty(_assetBundlePath) && Directory.Exists(_assetBundlePath))
        {
            switch (versionConfig.assetAccess)
            {
                case InstalledAsset.NullAsset:
                    CopyNullAssetResources(_assetBundlePath, streamingPath);
                    break;
                case InstalledAsset.HalfAsset:
                    CopyHalfAssetResources(_assetBundlePath, streamingPath);
                    break;
                case InstalledAsset.FullAsset:
                case InstalledAsset.IngoreDownLoad:
                    CopyFullAssetResources(_assetBundlePath, streamingPath);
                    break;
            }
            Debug.LogFormat("资源拷贝完成({0}),从 {1} 到 {2}", versionConfig.assetAccess, _assetBundlePath, streamingPath);
        }
        else
        {
            Debug.LogWarningFormat("AssetBundle路径为空或不存在: {0},导出工程将不包含游戏资源", _assetBundlePath);
        }
        // if (!string.IsNullOrEmpty(_assetBundlePath) && Directory.Exists(_assetBundlePath))
        // {
        //     switch (versionConfig.assetAccess)
        //     {
        //         case InstalledAsset.NullAsset:
        //             CopyNullAssetResources(_assetBundlePath, streamingPath);
        //             break;
        //         case InstalledAsset.HalfAsset:
        //             CopyHalfAssetResources(_assetBundlePath, streamingPath);
        //             break;
        //         case InstalledAsset.FullAsset:
        //         case InstalledAsset.IngoreDownLoad:
        //             CopyFullAssetResources(_assetBundlePath, streamingPath);
        //             break;
        //     }
        //     Debug.LogFormat("资源拷贝完成({0}),从 {1} 到 {2}", versionConfig.assetAccess, _assetBundlePath, streamingPath);
        // }
        // else
        // {
        //     Debug.LogWarningFormat("AssetBundle路径为空或不存在: {0},导出工程将不包含游戏资源", _assetBundlePath);
        // }
        // 关键设置:导出为Gradle工程而非直接打APK
        EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
@@ -908,6 +915,46 @@
        }
    }
    /// <summary>
    /// 导出 Gradle 工程前清理 Assets/Plugins/Android(保留 libs 目录)
    /// </summary>
    static void CleanupPluginsAndroidForExport()
    {
        var androidPluginPath = Path.Combine(Application.dataPath, "Plugins/Android");
        if (!Directory.Exists(androidPluginPath))
            return;
        Debug.Log("开始清理 Assets/Plugins/Android(保留 libs 目录)...");
        // 删除所有子目录(除了 libs)
        var subDirs = Directory.GetDirectories(androidPluginPath);
        foreach (var dir in subDirs)
        {
            var dirName = Path.GetFileName(dir);
            if (dirName != "libs")
            {
                Directory.Delete(dir, true);
                Debug.LogFormat("已删除 Plugins/Android/{0} 目录", dirName);
            }
        }
        // 删除根目录下的所有文件(保留 .aar 和 .aar.meta)
        var rootFiles = Directory.GetFiles(androidPluginPath);
        foreach (var file in rootFiles)
        {
            var fileName = Path.GetFileName(file);
            if (fileName.EndsWith(".aar") || fileName.EndsWith(".aar.meta"))
            {
                Debug.LogFormat("已保留文件: {0}", fileName);
                continue;
            }
            File.Delete(file);
            Debug.LogFormat("已删除文件: {0}", fileName);
        }
    }
    static BuildTargetGroup GetBuildTarget()
    {
#if UNITY_ANDROID