Search code examples
ethereumnethereum

Nethereum works well in unity editor, but not in android device


I'm using nethereum & unity with infura. (I'm developing an DApp.)

I wrote some code for minting new NFT, and tested, and it worked very well.

However, after build, it doesn't work in android device.

So I checked an error using android logcat, but there is no error.

Below is the async function that I used for test, the code to get the balance of account and save it.

async Task GetBalance()
{
    Debug.Log("Before : " + balance);
    balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address);
    Debug.Log("After : " + balance);
}

And I excuted this code in IEnumerator.

Task balanceTask = GetBalance();
yield return new WaitUntil(() => balanceTask.IsCompleted);
Debug.Log("Balance (Wei) = " + balance);
float balanceEth = (float)UnitConversion.Convert.FromWei(balance);
Debug.Log("Balance (Eth) = " + balanceEth);

Below is the result.

Before : -1
Balance (Wei) = -1
Balance (Eth) = -1E -18

Initial value of Balance is -1, and second Debug.Log() doesn't work. There is nothing that appeared to be an error. It's just skipped, and it goes on.

Additionally, I checked that the number of received requests of the infura server remained the same. In my opinion, nethereum fails to send request to the infura, and that makes Debug.Log() skipped.... but I don't know.

I'm confused because it works in editor, but not in device. Can you give me any advice?


Solution

  • I got it!! After I changed Scripting Backend (unity-build settings-player settings-other settings) IL2CPP to Mono, there is no error and my code perfectly works. I don't know why, but if you are struggle with this problem, this can be one of the solution. (maybe..?)