[fix] 修复生成桥接函数时错误使用editor环境的dll,导致NativeArray之类的类型与打包的aot dll不一致,进而生成桥接签名错误的bug。目前直接从裁剪后的AOT dll目录读取,但缺点是需要先build一次生成AOT dll,再生成桥接函数。

main
walon 2022-11-29 17:11:25 +08:00
parent 5270f307b9
commit 93f855f8ae
5 changed files with 27 additions and 8 deletions

View File

@ -51,16 +51,22 @@ namespace HybridCLR.Editor.Commands
GenerateMethodBridge(true);
}
static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target)
{
return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetAssembliesPostIl2CppStripDir(target),
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target))
);
}
public static void GenerateMethodBridge(bool compileDll)
{
// 此处理论会有点问题,打每个平台的时候,都得针对当前平台生成桥接函数
// 但影响不大,先这样吧
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
if (compileDll)
{
CompileDllCommand.CompileDllActiveBuildTarget();
}
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(CreateBuildTargetAssemblyResolver(target), SettingsUtil.HotUpdateAssemblyNames))
{
var analyzer = new Analyzer(new Analyzer.Options
{

View File

@ -124,7 +124,7 @@ namespace HybridCLR.Editor.Meta
return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)),
new UnityPluginAssemblyResolver(),
new UnityAOTAssemblyResolver(),
new UnityDotNetAOTAssemblyResolver(),
new UnityEditorAssemblyResolver());
}
}

View File

@ -9,12 +9,25 @@ using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class UnityAOTAssemblyResolver : IAssemblyResolver
public class UnityDotNetAOTAssemblyResolver : IAssemblyResolver
{
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
//
#if !UNITY_2021_1_OR_NEWER
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot/{assemblyName}.dll";
#else
#if UNITY_STANDALONE_WIN
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-win32/{assemblyName}.dll";
#elif UNITY_STANDALONE_OSX || UNITY_IOS
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-macos/{assemblyName}.dll";
#elif UNITY_STANDALONE_LINUX || UNITY_ANDROID
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-linux/{assemblyName}.dll";
#else
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-linux/{assemblyName}.dll";
#endif
#endif
if (File.Exists(assemblyFile))
{
Debug.Log($"UnityAOTAssemblyResolver.ResolveAssembly:{assemblyFile}");

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 029bc0368e1ada342aa29a18d4fae879
guid: 87ece9687eaa17648bdc9d2c9bf30520
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,6 +1,6 @@
{
"name": "com.focus-creative-games.hybridclr_unity",
"version": "1.1.0",
"version": "1.1.1",
"displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime",