MetaMask / metamask-android-sdk

MetaMask SDK for Android
Other
41 stars 13 forks source link

[Bug]: Got a crash after upload to Store #102

Closed thanhduy26091995 closed 5 months ago

thanhduy26091995 commented 6 months ago

Provide environment information

App can run successfully on Debug build. But after publish to Play store, it got a unexpected crash

Fatal Exception: mn.j0: lateinit property ecies has not been initialized at io.metamask.androidsdk.Crypto.generatePrivateKey(Crypto.java:1) at io.metamask.androidsdk.KeyExchange.reset(KeyExchange.java:1) at io.metamask.androidsdk.CommunicationClient$clearSession$1.invoke(CommunicationClient.java:2) at io.metamask.androidsdk.CommunicationClient$clearSession$1.invoke(CommunicationClient.java:1) at io.metamask.androidsdk.SessionManager$clearSession$1.invokeSuspend(SessionManager.java:1) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:11) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:1) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:1) at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java:1) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:1) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:1) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:1) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:1)

MetaMask Android SDK Version

0.5.0

MetaMask Mobile app Version

7.16.0

Android Version

14.0

Describe the Bug

App crash after publish to Play store

Expected Behavior

Not crash and can use normally

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

No response

To Reproduce

thanhduy26091995 commented 6 months ago

Do we have any proguard config?

elefantel commented 5 months ago

@thanhduy26091995 I see you have closed the issue. Is it no longer relevant or valid?

thanhduy26091995 commented 5 months ago

Hi @elefantel I added config to my proguard file and it's working fine. But sometimes, I got the same issue with this issue https://github.com/MetaMask/metamask-android-sdk/issues/95 https://github.com/MetaMask/metamask-android-sdk/issues/59#issuecomment-1871052119 Not sure it's come from SDK or Native wallet app

elefantel commented 5 months ago

@thanhduy26091995 Thanks for the feedback! Could you please share your proguard with the config you added to your app? I'm trying to figure out how that would fix the crash? I can imagine it does some refactor to fix the uninitialised lateinit. We will have a look at this to ensure it's fixed.

On the other issue that you often get, your link is broken, but I think it's this one? https://github.com/MetaMask/metamask-android-sdk/issues/95 Do you have a way definite way to reproduce it? Would appreciate some steps. Thanks again!

thanhduy26091995 commented 5 months ago

Hi @elefantel Thanks for replying Here is my proguard config: -keep class io.metamask.androidsdk.** { *; } Put this config then release build will fine.

  1. Also I totally agreed with you about the checking lateinit before using it first Let say in my business, I want to every time user use the app, they must connect wallet again Then on the init block of viewmodel, I called ethereum.disconnect(true) to force disconnect. If I call the function from debug mode, it's working fine. But for the release mode, it will be crash by using the lateinit before init.

  2. For the non-response of the app, let me try again then give you a logs. I usually had this issue, then I have to close both my app and metamask to let the service start to bind again.

thanhduy26091995 commented 5 months ago

A step is just a simple case

  1. Open Dapp
  2. Call function ethereum.connect()
  3. Metamask app open, then nothing happen. I have to close both dApp and metamask to make it bind again A log here

Info: SDK version: 0.5.1 ; Metamask app version: 7.17.0

2024-03-14 17:05:16.630 11684-11684 MM_ANDROID_SDK D Ethereum:: connecting... 2024-03-14 17:05:16.683 11684-11684 MM_ANDROID_SDK D SessionManager:: Session duration extended by: 7.0 days 2024-03-14 17:05:16.684 11684-11684 MM_ANDROID_SDK D Analytics: sdk_connect_request_started 2024-03-14 17:05:16.687 11684-11684 MM_ANDROID_SDK D Ethereum:: Requesting ethereum accounts 2024-03-14 17:05:16.689 11684-11684 MM_ANDROID_SDK D Ethereum:: Sending request EthereumRequest(id=1710410716688, method=eth_requestAccounts, params=null) 2024-03-14 17:05:16.689 11684-11684 MM_ANDROID_SDK D CommunicationClient:: sendRequest - not yet connected to metamask, binding service first 2024-03-14 17:05:16.689 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Queued job 2024-03-14 17:05:16.689 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Binding service 2024-03-14 17:05:16.690 11684-11684 MM_ANDROID_SDK E CommunicationClient:: NameNotFoundException io.metamask.qa 2024-03-14 17:05:16.787 11684-11684 MM_ANDROID_SDK D Ethereum:: Sending request EthereumRequest(id=1710410716786, method=eth_chainId, params=null) 2024-03-14 17:05:16.787 11684-11684 MM_ANDROID_SDK D CommunicationClient:: sendRequest - not yet connected to metamask, binding service first 2024-03-14 17:05:16.787 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Queued job 2024-03-14 17:05:16.787 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Binding service 2024-03-14 17:05:16.789 11684-11684 MM_ANDROID_SDK E CommunicationClient:: NameNotFoundException io.metamask.qa 2024-03-14 17:05:16.897 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Initiating key exchange 2024-03-14 17:05:16.901 11684-11684 MM_ANDROID_SDK D Sending key exchange KEY_HANDSHAKE_SYN 2024-03-14 17:05:16.904 11684-11684 MM_ANDROID_SDK D Sending key exchange KEY_HANDSHAKE_ACK 2024-03-14 17:05:16.934 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Keys exchanged 2024-03-14 17:05:16.934 11684-11684 MM_ANDROID_SDK D KeyExchange:: Key exchange complete 2024-03-14 17:05:16.952 11684-11684 MM_ANDROID_SDK D CommunicationClient:: Sending originator info: {"originatorInfo":{"apiVersion":"0.5.1","icon":

thanhduy26091995 commented 5 months ago

Hi @elefantel updated log

elefantel commented 5 months ago

Hey @thanhduy26091995 thanks for the detailed feedback! I have reopened the issue so that we can track it nicely.

I think we have fixed the lateinit issue in this merge request https://github.com/MetaMask/metamask-android-sdk/pull/107. Let me know if this fixes your issue (I suppose test with the proguard removed just as before?)

elefantel commented 5 months ago

On the issue of nothing happening during binding, I haven't managed to reproduce this issue so far. I have tried:

The logs you shared above seem truncated at the originator info? I have updated the logging in this merge request https://github.com/MetaMask/metamask-android-sdk/pull/108.

I have also created a gist here showing how my logs look like during a connection

thanhduy26091995 commented 5 months ago

Hi @elefantel , thanks for the quick feedback I will wait for the bump version 0.5.2 to test again

thanhduy26091995 commented 5 months ago

About the connection issue.

Yeah I already saw your gist log. Your log will be the same with mine in case it can connect successfully. But the rate of successfully is not 100% After fews day investigate, I found that some case could show error

Case 1: Put the DApp and metamask in the background as a long time, then open phone and try to connect DApp with Metamask => This case normally lead to nothing happen on Metamask app

Case 2: Quick access to the connect function after open app (I guess that the connection between DApp and Metamask haven't done yet). After wait maybe 30 seconds, all the function can work as a normal

Case 3: Could it be related with the device I used? Some device will take a long time to let service binding success

elefantel commented 5 months ago

Great feedback as always! Thanks, we will try reproducing with these use cases. In the meantime 0.5.2 is now out so the primary issue should be resolved 🎉

elefantel commented 5 months ago

@thanhduy26091995 how did the 0.5.2 release go? Did it fix the issue of the crash?

thanhduy26091995 commented 5 months ago

Hi @elefantel , the crash has ben fixed. But the issue related Metamask do nothing action sometime happens. I will create another ticket for this

elefantel commented 5 months ago

Perfect, thank you! Yes create another one for the other issue and provide as much details as you can. Thanks a lot!