'Android OkHttp - Clear Cookies Manually

I'm using Android app with Retrofit and OkHttp Client. Now I need a way to manually remove cookies from my application and I'm not sure how. I've tried writing a code like this in my project, but still wasn't able to properly remove/clear the cookies:

val cookieManager = CookieManager()
cookieManager.cookieStore.removeAll()

Here's how I've setup OkHttp in my project:

@ExperimentalSerializationApi
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {

    @Provides
    @Singleton
    fun provideHttpClient(): OkHttpClient {
        val cookieManager = CookieManager()
        return OkHttpClient.Builder()
            .readTimeout(15, TimeUnit.SECONDS)
            .connectTimeout(15, TimeUnit.SECONDS)
            .cookieJar(JavaNetCookieJar(cookieManager))
            .build()
    }

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source