Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnityGameFramework.Runtime.dll.bytes #3

Open
MisterNatureQ opened this issue Jun 27, 2022 · 3 comments
Open

UnityGameFramework.Runtime.dll.bytes #3

MisterNatureQ opened this issue Jun 27, 2022 · 3 comments

Comments

@MisterNatureQ
Copy link

windows 64位打包之后 huatuo 报错 ; ExecutionEngineException: metadata field not match 报错的是 UnityGameFramework.Runtime.dll.bytes; 注释掉 s_AotDllList 中的 "UnityGameFramework.Runtime" 后运行正常 ;
疑问
1 看代码 /{dll} 到 /{dll}.bytes 是不是仅仅只是 拷贝 并没有更改
2 LoadMetadataForAOTAssembly 没有理解这里的公用; 在这里注释掉 "UnityGameFramework.Runtime" 修改是不是有问题 和 作者本身的想法冲突了

@MisterNatureQ
Copy link
Author

调整之后可以了

// 编译Dll
private static void CompileDll(string buildDir, BuildTarget target)
{
var group = BuildPipeline.GetBuildTargetGroup(target);

        // ScriptCompilationSettings 如何构建脚本的信息
        // https://docs.unity3d.com/cn/2020.2/ScriptReference/Build.Player.ScriptCompilationSettings.html
        ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();
        // 编译脚本所针对的平台组
        scriptCompilationSettings.group = group;
        // 	编译脚本所针对的平台组
        scriptCompilationSettings.target = target;
        // 编译脚本时要使用的特定编译器选项
        // 创建文件夹
        CreateDirIfNotExists(buildDir);

        // 将用户脚本编译为一个或多个程序集 返回 assemblies 编译后的程序集的集合 typeDB 由脚本编译调用生成的类型信息
        // [PlayerBuildInterface.CompilePlayerScripts](https://docs.unity3d.com/cn/current/ScriptReference/Build.Player.PlayerBuildInterface.CompilePlayerScripts.html)
        // [Unity 3d 编辑器程序集编译API - 笔记](https://www.jianshu.com/p/7ffca90fa853)
        ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, buildDir);

        // assemblies 编译后的程序集的集合
        // https://docs.unity3d.com/cn/current/ScriptReference/Build.Player.ScriptCompilationResult.html
        foreach (var ass in scriptCompilationResult.assemblies)
        {
            Debug.LogFormat($"CompileDll compile assemblies:{ass}; buildDir:{buildDir}; Application.dataPath{Application.dataPath}; group:{group}; BuildTarget:{target}; ");
        }
        
        // 需要热跟新Dll
        var hotfixDlls = new List<string>()
        {
            "Game.Hotfix.dll",
        };

        foreach(var dll in hotfixDlls)
        {
            string dllPath = $"{GetDllBuildOutputDirByTarget(target)}/{dll}";
            string dllBytesPath = $"{GetAssetBundleTempDirByTarget(target)}/{dll}.bytes";
            File.Copy(dllPath, dllBytesPath, true);
            Debug.LogFormat("hotfixDlls CompileDll :{0} dllBytesPath:{1}", dllPath, dllBytesPath);
        }
        
        ////////////////////////////////////////////////////////////////////////////////
        
        // 用于补充元数据的dll
        var aotDlls = new List<string>()
        {
            "mscorlib.dll",
            "System.dll",
            "System.Core.dll", // 如果使用了Linq,需要这个
            "LitJson.dll",// ok
            "protobuf-net.dll",// ok
            "GameFramework.dll",// error 
            "UnityGameFramework.Runtime.dll",// error
        };

        string aotDllDir = $"{AssembliesPostIl2CppStripDir}/{target}";
        foreach(var dll in aotDlls)
        {
            // 这个路径是错误的
            //string dllPath = $"{GetDllBuildOutputDirByTarget(target)}/{dll}";
            // 应该使用这个路径
            string dllPath = $"{aotDllDir}/{dll}";
            if(!File.Exists(dllPath))
            {
                // \HuatuoData\AssembliesPostIl2CppStrip\StandaloneWindows64 windows 目前看是在这个目录
                // \Temp\HuaTuo\build\StandaloneWindows64 这个目录下面是没有的
                Debug.LogError($"ab中添加AOT补充元数据dll:{dllPath} 时发生错误,文件不存在。需要构建一次主包后才能生成裁剪后的AOT dll");
                continue;
            }
            string dllBytesPath = $"{GetAssetBundleMetadataAssemblyAssetByTarget(target)}/{dll}.bytes";
            File.Copy(dllPath, dllBytesPath, true);
            Debug.LogFormat("metadata_hotfixDlls CompileDll :{0} dllBytesPath:{1}", dllPath, dllBytesPath);
        }
        
        AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
    }

@DangoRyn
Copy link
Owner

前两天没看到不好意思,dll不同会导致metadata无法匹配,原先是我已经编译好的放在上面的所以不会有异常。如果自行有修改就需要重新拷贝一份新的dll这里没有详细说明。很感谢你分享的修改的方案。

@maki0315
Copy link

maki0315 commented Jul 21, 2022

我也遇到过这个问题,我这里有个问题请教一下,关于补充元数据的dll UnityGameFramework.Runtime 我用于热更打包发布后使用是没有问题的,但后来我在 UnityGameFramework.Runtime 新增了方法,重新拷到要打的AB包里经行热更,用于补充元数据,运行后显示不匹配(metadata field not match ),不知道这个是什么原因,
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants