diff --git a/Editor/CodeGen/MethodBridge/Generator.cs b/Editor/CodeGen/MethodBridge/Generator.cs index dfc743e..669818a 100644 --- a/Editor/CodeGen/MethodBridge/Generator.cs +++ b/Editor/CodeGen/MethodBridge/Generator.cs @@ -843,7 +843,7 @@ namespace HybridCLR.CodeGen.MethodBridge private void CollectStructDefs(List methods, HashSet structTypes) { - ICorLibTypes corLibTypes = _genericMethods[0].Method.Module.CorLibTypes; + ICorLibTypes corLibTypes = _genericMethods.Count > 0 ? _genericMethods[0].Method.Module.CorLibTypes : null; foreach (var method in methods) { diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 6bb57b9..b0a4363 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -55,6 +55,12 @@ namespace HybridCLR.Commands GenerateMethodBridgeAndReversePInvokeWrapper(target); } + public static void GenerateEmptyMethodBridgeAndReversePInvokeWrapper(BuildTarget target) + { + string outputFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.inc"; + GenerateMethodBridgeCppFile(new List(), new List(), new List(), outputFile); + } + public static void GenerateMethodBridgeAndReversePInvokeWrapper(BuildTarget target) { string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target); diff --git a/Editor/Commands/PrebuildCommand.cs b/Editor/Commands/PrebuildCommand.cs index 6f0e8e2..cb06f31 100644 --- a/Editor/Commands/PrebuildCommand.cs +++ b/Editor/Commands/PrebuildCommand.cs @@ -43,6 +43,11 @@ namespace HybridCLR.Commands // These generation depend on HotUpdateDlls LinkGeneratorCommand.GenerateLinkXml(target); + // Because some build targets will link the generated AOT dll before generating method bridge, + // so we need to generate an empty method bridge and reverse PInvoke wrapper first + // so that the generated AOT dll can be linked successfully + MethodBridgeGeneratorCommand.GenerateEmptyMethodBridgeAndReversePInvokeWrapper(target); + // Generate stripped aot dll StripAOTDllCommand.GenerateStripedAOTDlls(target);