Crash on Logout with "cookieJar was already accessed" Error in okta-idx-android 3.0.1

I’m using the okta-idx-android library version 3.0.1 to manage authentication in my Android app. The initial login flow works without issues, but I’m getting a crash when logging out and attempting to reinitialize the Okta client (using createClient function). Specifically, I’m receiving the following error message:

java.lang.IllegalStateException: cookieJar was already accessed, and can't be set.

This crash occurs when I navigate back to the login screen after logging out and re-call the createClient function.

Could you provide guidance on how to resolve this issue or best practices for handling logout and re-login using the Okta IDX SDK?

Additional Info:

  • Library version: okta-idx-android v3.0.1
  • Kotlin version: 1.9.0
  • Android API compile: 34
  • Android API target: 33

Below are the details of the logout implementation, crash logs,

Logout Function Code:

fun logout() {
    viewModelScope.launch {
        when (credential.revokeToken(RevokeTokenType.ACCESS_TOKEN)) {
            is OAuth2ClientResult.Error -> {
                // handle error
            }
            is OAuth2ClientResult.Success -> {
                // handle success and navigate to login screen
            }
        }
    }
}

Full Crash Log:

E/AndroidRuntime( 3247): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 3247): at com.typeiii.app.LoginActivity$createClient$1.invokeSuspend(LoginActivity.kt:126)
E/AndroidRuntime( 3247): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime( 3247): at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:363)
E/AndroidRuntime( 3247): at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
E/AndroidRuntime( 3247): at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:21)
E/AndroidRuntime( 3247): at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:88)
E/AndroidRuntime( 3247): at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
E/AndroidRuntime( 3247): at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
E/AndroidRuntime( 3247): at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
E/AndroidRuntime( 3247): at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
E/AndroidRuntime( 3247): at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
E/AndroidRuntime( 3247): at com.typeiii.app.LoginActivity.createClient(LoginActivity.kt:124)
E/AndroidRuntime( 3247): at com.typeiii.app.LoginActivity.onCreate(LoginActivity.kt:72)
E/AndroidRuntime( 3247): at android.app.Activity.performCreate(Activity.java:8051)
E/AndroidRuntime( 3247): at android.app.Activity.performCreate(Activity.java:8031)
E/AndroidRuntime( 3247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
E/AndroidRuntime( 3247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
E/AndroidRuntime( 3247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
E/AndroidRuntime( 3247): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
E/AndroidRuntime( 3247): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime( 3247): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime( 3247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
E/AndroidRuntime( 3247): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 3247): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 3247): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 3247): at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime( 3247): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3247): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime( 3247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime( 3247): Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@1c13901, Dispatchers.Main.immediate]
E/AndroidRuntime( 3247): Caused by: java.lang.IllegalStateException: cookieJar was already accessed, and can’t be set.
E/AndroidRuntime( 3247): at com.okta.authfoundation.NoSetAfterGetWithLazyDefaultFactory.setValue(NoSetAfterGetWithLazyDefaultFactory.kt:39)
E/AndroidRuntime( 3247): at com.okta.authfoundation.AuthFoundationDefaults.setCookieJar(AuthFoundationDefaults.kt:84)
E/AndroidRuntime( 3247): at com.okta.idx.kotlin.client.InteractionCodeFlow.(InteractionCodeFlow.kt:48)
E/AndroidRuntime( 3247): … 29 more

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.