App crash in setResultUrl

When asking for help in this category, please make sure to provide the following details:

  • SDK Version: 9.0.2
  • Platform: android

Hello,

I’m currently integrating the Web3Auth library in our Android application and have encountered a recurring crash affecting about 3% of our users. The crash error is as follows:

Fatal Exception: n7.L: lateinit property loginCompletableFuture has not been initialized
    at com.web3auth.core.Web3Auth$setResultUrl$3$1.invoke(Web3Auth.kt:254)
    at com.web3auth.core.Web3Auth$setResultUrl$3$1.invoke(Web3Auth.kt:232)
    at com.web3auth.core.Web3Auth.runOnUIThread$lambda-14(Web3Auth.kt:579)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8919)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

initialize & login code snippet

    fun connectWeb3Auth(web3auth: Web3Auth, isSign: Boolean = true) {
        state.postValue(WalletState.InProgress)
        val sessionResponse: CompletableFuture<Void> = web3auth.initialize()
        sessionResponse.whenComplete { _, error ->
            if (error == null) {
                val credentials = Credentials.create(web3auth.getPrivkey())
            } else {
                Timber.e("sessionResponse connectWeb3Auth error: ${error.message ?: "Something went wrong"}")
            }
        }
        auth.currentUser?.let { user ->
            user.getIdToken(true).addOnSuccessListener { result ->
                result.token?.let { token ->
                    val loginParams = web3AuthManager.prepareLoginParams(user.uid, token)
                    val loginCompletableFuture = web3auth.login(loginParams)
                    loginCompletableFuture.whenComplete { response, error ->
                        if (error == null) {
                            if (!response.userInfo?.dappShare.isNullOrEmpty())
                                KeyStoreManager.storeEncryptedData(context, user.uid, response.userInfo?.dappShare!!)
                            val credentials = Credentials.create(web3auth.getPrivkey())
                            web3AuthManager.enableMFA(web3auth,
                                success = {
                                    state.postValue(WalletState.ConnectedWallet(credentials.address))
                                    if (isSign) connectSignWeb3Auth(credentials)
                                }, error = {
                                    state.postValue(WalletState.Web3AuthFailed(it))
                                }
                            )
                        } else {
                            state.postValue(WalletState.Web3AuthFailed(error.message?:"error"))
                        }
                    }
                } ?: run {
                    state.postValue(WalletState.Web3AuthFailed("GetTokenResult null"))
                }
            }
        }
    }

Android Version Distribution:
Our crash analytics show that most crashes occur on devices running Android 14 (SDK 34), with significant contributions from Android 12 (SDK 31) and Android 13 (SDK 33). Other versions account for a much smaller portion of the crashes.

Could you please advise if:

  1. There is a known issue or workaround regarding the uninitialized loginCompletableFuture?
  2. Further initialization steps or configuration adjustments are required on our end?
  3. A patch or update is planned to address this error?

Any assistance or guidance to resolve this issue would be greatly appreciated. Please let me know if additional information or logs are required.

Thank you for your support!

Best regards,
Ron

Hello Ron,

Thank you for reaching out and providing such a thorough explanation of the issue you’re encountering. I understand how frustrating it can be to see these crashes affecting your users.

From your description and code snippet, it appears that the issue might be related to the loginCompletableFuture being accessed before it’s properly initialized. Here are a few things you could consider to potentially resolve this:

  1. Initialization Timing: Ensure that web3auth.initialize() completes successfully before attempting to call web3auth.login(). You might want to verify that no other operations are modifying the web3auth object in between these calls.

  2. Error Handling: You’ve captured errors with whenComplete, but ensure that any potential initialization issues are logged, which might help to understand if the problem starts there.

  3. Conditional Checks: Before proceeding to web3auth.login(), check if web3auth.isInitialized (if such a property is available) to ensure that initialization has completed properly.

Regarding your specific questions:

  • I recommend checking the Web3Auth GitHub repository or their release notes for any listed known issues or recent fixes related to the Android SDK.
  • I will flag this internally, and our support team might be able to provide further insight into potential configuration adjustments or upcoming patches.

Please feel free to share additional logs if they shed more light or if you observe any patterns in the crashes. Your effort in pinpointing affected Android versions helps as well, and our team will consider this information when investigating the issue.

Thank you for your patience and collaboration. We’re here to assist you in smoothing this out for your application.

Best regards,
[Your Name]

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

Hey @ron1, it’s not a known issue, will investigate the issue. Meanwhile, can you update the SDK to the latest version?

Do we have a tg group with your company?

Thanks for the update. We’ll update to the latest SDK version as recommended.

Regarding the Telegram group, I’d be happy to join; however, I’d prefer not to share my Telegram ID in a public forum. Could you please send me a private message or let me know an alternative way to provide my ID?

Thanks again for your help!

Hey @ron1 have shared you calendly link in DM, please schedule a call with me to debug the issue. I’m not able to reproduce the issue.