Back to Trending
RepositoryKotlinITItaly
GO

gotev/android-cookie-store

Android InMemory and persistent Cookie Store for HttpURLConnection and OkHttp, with extensions to easily sync cookies in Android WebViews.

196stars
21forks
3issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: httpurlconnection

#1 Repository of the month

1
TINIX TRENDING·Topic: okhttp

#1 Repository of the month

1
TINIX TRENDING·Topic: store

#1 Repository of the month

Android Cookie Store

Android Arsenal Android Weekly ktlint Maven Central PRs Welcome

Latest version Release Notes and Demo App | Demo App Sources

Android InMemory and persistent Cookie Store for HttpURLConnection and OkHttp, with extensions to easily sync cookies in Android WebViews.

Why?

Neither HttpURLConnection nor OkHttp provides a native and rapid way of storing cookies persistently on Android. This library aims to fill this gap, by implementing the standard java.net.InMemoryCookieStore in Kotlin, with extendability in mind.

With this library you have:

  • super tiny footprint (the library is only a bunch of classes)
  • an in memory only cookie store
  • a shared preferences backed cookie store which can survive app reboots
  • possibility to extend both to provide your own custom implementation which best fits your needs without reinventing the wheel for cookie management

Compatibility

Android API 16+

Getting started

Add this to your dependencies:

implementation "net.gotev:cookie-store:x.y.z"

Replace x.y.z with Maven Central

Usage

Create your Cookie Manager:

// Example extension function to demonstrate how to create both cookie stores
fun Context.createCookieStore(name: String, persistent: Boolean) = if (persistent) {
    SharedPreferencesCookieStore(applicationContext, name)
} else {
    InMemoryCookieStore(name)
}

val cookieManager = CookieManager(
    createCookieStore(name = "myCookies", persistent = true),
    CookiePolicy.ACCEPT_ALL
)

HttpURLConnection

To setup the default Cookie Manager:

CookieManager.setDefault(cookieManager)

OkHttp

Add the following dependency (suitable for JVM and Android):

implementation "net.gotev:cookie-store-okhttp:$cookieStoreVersion"

And when you build your OkHttpClient, set the Cookie Jar:

val okHttpClient = OkHttpClient.Builder()
    .cookieJar(JavaNetCookieJar(cookieManager))
    .build()

WebView

It's a common thing to obtain a cookie from an API and to open an authenticated web page inside an app which needs the cookie. You can find a complete working example in the demo app.

You have two ways of doing this:

  • Using WebKitSyncCookieManager
  • Using standard java.net.CookieManager

Using WebKitSyncCookieManager

val cookieManager = WebKitSyncCookieManager(
    store = createCookieStore(name = "myCookies", persistent = true),
    cookiePolicy = CookiePolicy.ACCEPT_ALL,
    onWebKitCookieManagerError = { exception ->
        // This gets invoked when there's internal webkit cookie manager exceptions
        Log.e("COOKIE-STORE", "WebKitSyncCookieManager error", exception)
    }
)

Then follow standard instructions from the Usage section to setup HttpURLConnection or OkHttp according to your needs.

Incoming Cookies will be automatically synced to WebKit's CookieManager. Syncing is unidirectional from WebKitSyncCookieManager to android.webkit.CookieManager to have a single source of truth and to prevent attacks coming from URLs loaded in WebViews. If you need bi-directional sync, think twice before doing it.

To clear cookies:

cookieManager.removeAll()

This will clear both the CookieStore and WebKit's Cookie Manager.

Using standard java.net.CookieManager

Cookies syncing is entirely up to you and manual.

To copy all cookies from the cookie store to the WebKit Cookie Manager:

cookieManager.cookieStore.syncToWebKitCookieManager()

Remember to do this before loading any URL in your web view.

To remove all cookies from the Cookie Store:

cookieManager.cookieStore.removeAll()

To remove all cookies from WebKit Cookie Manager:

android.webkit.CookieManager.getInstance().removeAll()

That's all folks!

Similar Projects

Discover other similar projects and AI models.

RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026
RepositoryKotlin
lysine-dev/okhttp

A meticulous HTTP client for the JVM, Android, and GraalVM.

47.1k
Nov 27, 2026
RepositoryKotlin
gkd-kit/gkd

基于无障碍,高级选择器,订阅规则的自定义屏幕点击安卓应用 | An Android APP with custom screen tapping based on Accessibility, Advanced Selectors, and Subscription Rules

45.7k
Nov 13, 2026
RepositoryKotlin
JunkFood02/Seal

🦭 Video/Audio Downloader for Android, based on yt-dlp

31.2k
Nov 25, 2026
RepositoryKotlin
InsertKoinIO/koin

Koin - pragmatic dependency injection for Kotlin & Kotlin Multiplatform. Koin DSL or Koin Annotations (JSR-330), compile safe with the Koin Compiler Plugin.

10.0k
Nov 6, 2026
RepositoryJava
yuliskov/SmartTube

Browse media content with your own rules on Android TV

36.8k
Nov 29, 2026
RepositoryC++
webview/webview

Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).

14.4k
Oct 22, 2026
RepositoryJava
Justson/AgentWeb

AgentWeb is a powerful library based on Android WebView.

9.4k
Sep 14, 2026