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

Unity: Error when building with IL2CPP #878

Closed
Cherden opened this issue Sep 28, 2022 · 22 comments
Closed

Unity: Error when building with IL2CPP #878

Cherden opened this issue Sep 28, 2022 · 22 comments

Comments

@Cherden
Copy link

Cherden commented Sep 28, 2022

I have a project that builds .NET4.X AOT with IL2CPP. I used the DLLs of net472dllsAOT.zip from release 4.8.0, which in itself do not show errors. Once I start to compiler, an error is shown reading ArgumentException: The Assembly WindowsBase is referenced by System.Reactive ('Assets/CoaBlockchainSDK/Plugins/Nethereum/System.Reactive.dll'). But the dll is not allowed to be included or could not be found.. When adding the WindowsBase.dll from my system to the project (as described here), compiling works but the app does not start due to some other errors (most likely because it is not on Windows).
Building with mono works fine.
I have tried previous releases, with net461dlls.zip, as well as netStandard but none of them seem to work.
Was anyone able to build with IL2CPP or is it even supported?

@Cherden Cherden changed the title Error when building with IL2CPP Unity: Error when building with IL2CPP Sep 28, 2022
@juanfranblanco
Copy link
Member

juanfranblanco commented Sep 28, 2022

Hi @Cherden

Yes those are packed by default, and specific to some projects. Try the subset of dlls in netStandardMinimalUnityAOT.zip
and yes you can build using ilcpp, this is why the emphasis on testing webgl, if it works there it works everywhere as it does ilcpp before webgl / wasm

@Cherden
Copy link
Author

Cherden commented Sep 28, 2022

Thank you for your fast reply @juanfranblanco.
Adding the dlls of netStandardMinimalUnityAOT.zip gave the error IWeb3 not found in my code. Was noticing that Nethereum.Web3.dll was missing and added Nethereum.Web3Lite.dll (as a first test) from netStandardAOT.zip (and subsequently Nethereum.BlockchainProcessing.dll due to Web3Lite depending on it).
Building worked fine, but got the error JsonException: No parameterless constructor defined for 'Nethereum.JsonRpc.Client.RpcMessages.RpcParametersJsonConverter'. while running my app. Following this advice, I then added the link.xml referenced in the comment but it then did not compile anymore showing some references missing during linking.

il2cppOutput/Nethereum.Unity.cpp:33647: error: undefined reference to 'EnableEthereum'
il2cppOutput/Nethereum.Unity.cpp:33689: error: undefined reference to 'EthereumInit'
il2cppOutput/Nethereum.Unity.cpp:33722: error: undefined reference to 'GetChainId'
il2cppOutput/Nethereum.Unity.cpp:33743: error: undefined reference to 'IsMetamaskAvailable'
il2cppOutput/Nethereum.Unity.cpp:33753: error: undefined reference to 'GetSelectedAddress'
il2cppOutput/Nethereum.Unity.cpp:33787: error: undefined reference to 'Request'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'

@juanfranblanco
Copy link
Member

juanfranblanco commented Sep 28, 2022

Web3Lite is when you don't need to use any signing libraries, as it does not force you to include the Account project. If not use Nethereum.Web3.
Regarding linking make sure you include all the libraries. I am making a new release at the moment so i will create another subset "Common" which is not minimal like the other for webgl.

@juanfranblanco
Copy link
Member

@Cherden
Copy link
Author

Cherden commented Sep 29, 2022

Added the dlls from netStandardUnityCommonAOT.zip (I think that's the one your were talking about, right?) and:

  • NBitcoin.dll is missing System.Buffers
  • Microsoft.Extensions.Logging.Abstractions.dll is missing System.Memory.

I'm also getting this warning: Assuming assembly reference 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' used by 'Nethereum.Web3' matches identity 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60' of 'Microsoft.Extensions.Logging.Abstractions', you may need to supply runtime policy
System.Buffers I found in a previous release, but don't know where to get System.Memory.
Do you not get the unresolved references when adding it to a fresh project? I'm using Unity 2021.1.28f1, scripting backend IL2CPP and Api Compability Level .Net 4.x for reference.

@juanfranblanco
Copy link
Member

hmm you dont seem to be targetting netstandard, .netx would expect that. I have updated the packages to include the metamask js file, that solves:

il2cppOutput/Nethereum.Unity.cpp:33647: error: undefined reference to 'EnableEthereum'
il2cppOutput/Nethereum.Unity.cpp:33689: error: undefined reference to 'EthereumInit'
il2cppOutput/Nethereum.Unity.cpp:33722: error: undefined reference to 'GetChainId'
il2cppOutput/Nethereum.Unity.cpp:33743: error: undefined reference to 'IsMetamaskAvailable'
il2cppOutput/Nethereum.Unity.cpp:33753: error: undefined reference to 'GetSelectedAddress'
il2cppOutput/Nethereum.Unity.cpp:33787: error: undefined reference to 'Request'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'

@Cherden
Copy link
Author

Cherden commented Sep 29, 2022

Yes, I'm targeting .Net 4.x. I am using the dlls from net472dllsAOT.zip now (as it seems I need those for my target version). There I get the error that System.Reactive.dll requires WindowsBase when starting the build process.

@juanfranblanco
Copy link
Member

i have not packaged those yet, dont include "Nethereum.RPC.Reactive.dll" as i assume you wont be using that, that will solve your dependency to system reactive.

@Cherden
Copy link
Author

Cherden commented Sep 29, 2022

Removing "Nethereum.RPC.Reactive.dll" started the il2cpp build process, but gave the linking error:

15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol EnableEthereum referenced in function MetamaskInterop_EnableEthereum_m7CD4EC4079D1920ECE7A9B760B33E7389FB1014B
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol EthereumInit referenced in function MetamaskInterop_EthereumInit_mFAF743C17A74CD8774104FA08E138933CF286010
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol GetChainId referenced in function MetamaskInterop_GetChainId_m073C0682DE3C6D10DAE051A114F6496FBAA3BE89
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol IsMetamaskAvailable referenced in function MetamaskInterop_IsMetamaskAvailable_m2DFD241091FF52BD9EA0BE6C9C6E52CE1013D8D0
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol GetSelectedAddress referenced in function MetamaskInterop_GetSelectedAddress_m35DE31F74F79BE9B74F56E9A712AAC68E665B24D
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol Request referenced in function MetamaskInterop_Request_mF44E21AD1B14F26BEFC880CD29EEA0211733AA69
15B328623AB43E66F2EAA7F87853403D.obj : error LNK2019: unresolved external symbol RequestRpcClientCallback referenced in function MetamaskInterop_RequestRpcClientCallback_mBA1E008EA0255D5531CA61967705E190C9547384

Do I need to do something with the NethereumMetamask.jslib that you added in the other release?

@juanfranblanco
Copy link
Member

juanfranblanco commented Sep 29, 2022

@Cherden
Copy link
Author

Cherden commented Sep 29, 2022

After adding NethereumMetamask.jslib the linking error reads:

il2cppOutput/Nethereum.Unity.cpp:33647: error: undefined reference to 'EnableEthereum'
il2cppOutput/Nethereum.Unity.cpp:33689: error: undefined reference to 'EthereumInit'
il2cppOutput/Nethereum.Unity.cpp:33722: error: undefined reference to 'GetChainId'
il2cppOutput/Nethereum.Unity.cpp:33743: error: undefined reference to 'IsMetamaskAvailable'
il2cppOutput/Nethereum.Unity.cpp:33753: error: undefined reference to 'GetSelectedAddress'
il2cppOutput/Nethereum.Unity.cpp:33787: error: undefined reference to 'Request'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'

@juanfranblanco
Copy link
Member

?? that should not happen you are using 4.8.0 no?

@Cherden
Copy link
Author

Cherden commented Sep 29, 2022

Not 100% sure which one unity uses, but max. 4.7.1.

@juanfranblanco
Copy link
Member

Nethereum 4.8.0 I meant

@Cherden
Copy link
Author

Cherden commented Sep 30, 2022

Oh, yes. Using these dlls: net472dllsAOT.zip with added link.xml and NethereumMetamask.jslib, and removed the Nethereum.RPC.Reactive.dll.

@juanfranblanco
Copy link
Member

@Cherden I have released now the 470 dlls also updated the starter demo https://github.com/Nethereum/Unity3dSampleTemplate/blob/master/README.md hopefully this can help you

@ajeshyohan
Copy link

I also faced the same issue, so to test I cloned https://github.com/Nethereum/Unity3dSampleTemplate.git this and opened in Unity changed the scripting backend to IL2CPP, same error coming when making a build

il2cppOutput/Nethereum.Unity.cpp:33647: error: undefined reference to 'EnableEthereum'
il2cppOutput/Nethereum.Unity.cpp:33689: error: undefined reference to 'EthereumInit'
il2cppOutput/Nethereum.Unity.cpp:33722: error: undefined reference to 'GetChainId'
il2cppOutput/Nethereum.Unity.cpp:33743: error: undefined reference to 'IsMetamaskAvailable'
il2cppOutput/Nethereum.Unity.cpp:33753: error: undefined reference to 'GetSelectedAddress'
il2cppOutput/Nethereum.Unity.cpp:33787: error: undefined reference to 'Request'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'
il2cppOutput/Nethereum.Unity.cpp:33829: error: undefined reference to 'RequestRpcClientCallback'

image

@Cherden
Copy link
Author

Cherden commented Oct 4, 2022

Have been trying with the net472UnityCommonAOT.zip dlls and was missing System.Memory.dll, System.Buffers.dll and System.Runtime.CompilerServices.Unsafe.dll (unresolved dependency errors) which I added from net472dllsAOT.zip. Additionally I have still the link.xml included mentioned above. Getting the link error:

661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol EnableEthereum referenced in function MetamaskInterop_EnableEthereum_m3C8FE3D115E61D46D32FD4DBFC24568E8AA82DC7
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol EthereumInit referenced in function MetamaskInterop_EthereumInit_m257B209F754E65435C0179077501EC547ADD8744
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol GetChainId referenced in function MetamaskInterop_GetChainId_m55F44B355DBB1B1A24D6E3B9E75E03598DE91C6B
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol IsMetamaskAvailable referenced in function MetamaskInterop_IsMetamaskAvailable_m0A2DC8618A8B93A33AB0D56A5621B715EADC0B75
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol GetSelectedAddress referenced in function MetamaskInterop_GetSelectedAddress_m5D0286F3507588EE5CC70E4E2C39FB33A8D210EF
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol Request referenced in function MetamaskInterop_Request_m3AD7DA0CEAB5AAD5F70846F079CE9F4179B425E7
661CF9B3C1063DDA3CEE8A0F9E114B27.obj : error LNK2019: unresolved external symbol RequestRpcClientCallback referenced in function MetamaskInterop_RequestRpcClientCallback_m33D91153B83F3907187E5B3EAA0A96F88C34413D
C:\UnityProject\Library\il2cpp_cache\linkresult_A1ED5825F703EC08F27FE6EF0E8B91D9\GameAssembly.dll : fatal error LNK1120: 7 unresolved externals

@juanfranblanco
Copy link
Member

@Cherden i have not had any issues ith those dlls. Regarding the issues external symbols I am going to move the MM part to another library so it can be excluded when the target is not webgl.

@juanfranblanco
Copy link
Member

Ok I have separated now the MM from the core Unity component. ?The issue was that the jslib was not inluded in other platforms, so in this scenario is much better to isolate both components for that platform only.
image
image
If included you need to mark them as webgl so they are only included when compiling for the browser.
image
Example running Il2cpp,
image

Release here:
https://github.com/Nethereum/Nethereum/releases/tag/4.10.0

@Cherden
Copy link
Author

Cherden commented Oct 4, 2022

Works now 🎉 . Thank you very much for your support @juanfranblanco.

@Cherden Cherden closed this as completed Oct 4, 2022
@juanfranblanco
Copy link
Member

Thanks to you too :)

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