On this page
If your project is Android-only, Retrofit is a safe, well-understood default. If you share networking with iOS through Kotlin Multiplatform, Ktor Client is the natural fit. Everything else in this comparison refines that headline.
The same endpoint in both
interface GithubApi {
@GET("users/{user}/repos")
suspend fun repos(@Path("user") user: String, @Query("per_page") perPage: Int = 30): List<RepoDto>
}
// val api = retrofit.create(GithubApi::class.java); api.repos("android")val client = HttpClient(OkHttp) { // engine: OkHttp on Android
install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) }
install(HttpTimeout) { requestTimeoutMillis = 15_000 }
defaultRequest { url("https://api.github.com/") }
expectSuccess = true // throw on non-2xx
}
class GithubApi(private val client: HttpClient) {
suspend fun repos(user: String, perPage: Int = 30): List<RepoDto> =
client.get("users/$user/repos") { parameter("per_page", perPage) }.body()
}Comparison
| Aspect | Retrofit | Ktor Client |
|---|---|---|
| Style | Declarative annotated interfaces | Imperative DSL (request builders) |
| Platforms | JVM and Android | Kotlin Multiplatform: Android, iOS, JVM, JS, native |
| Transport | OkHttp | Pluggable engines (OkHttp, CIO, Darwin on iOSβ¦) |
| Serialization | Converters (kotlinx.serialization, Moshiβ¦) | ContentNegotiation plugin (kotlinx.serialization) |
| Cross-cutting concerns | OkHttp interceptors and authenticators | Plugins (Auth, Logging, HttpTimeout, retry) |
| Testing | MockWebServer, fakes | MockEngine, fakes |
| Ecosystem on Android | Very mature, huge community knowledge | Mature and growing, strong in KMP |
Testing with Ktor's MockEngine
@Test
fun `parses repos`() = runTest {
val engine = MockEngine { request ->
assertEquals("/users/android/repos", request.url.encodedPath)
respond("""[{"id":1,"name":"nowinandroid"}]""", headers = headersOf(HttpHeaders.ContentType, "application/json"))
}
val client = HttpClient(engine) { install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } }
val repos = GithubApi(client).repos("android")
assertEquals("nowinandroid", repos.single().name)
}Real scenarios
Android-only app with existing Retrofit code
Keep Retrofit. Migration cost brings no user benefit.
New KMP app (Android + iOS)
Ktor in commonMain with the OkHttp engine on Android and the Darwin engine on iOS.
Gradual KMP adoption
Keep Retrofit in the Android app, and write new shared modules with Ktor behind a repository interface.
Common mistakes
- Creating a new
HttpClientper request in Ktor. Create one and share it, then close it when it's no longer needed. - Forgetting
expectSuccess = true(or manual status checks) in Ktor, which silently parses error bodies. - Mixing both clients for the same API, which doubles configuration (auth, timeouts, logging).
Frequently asked questions
Is Ktor slower than Retrofit on Android?
With the OkHttp engine, both use the same transport. Differences are rarely significant compared with network latency.
Can Retrofit be used in Kotlin Multiplatform?
Retrofit targets the JVM and Android. For shared code that also runs on iOS, use a multiplatform client like Ktor.
Which is easier for beginners?
Retrofit's annotated interfaces are very approachable, and most Android tutorials use them. Ktor's DSL is also straightforward once you know coroutines.
Conclusion
Retrofit remains an excellent default for Android-only apps. Ktor Client is the better fit when networking must be shared across platforms with Kotlin Multiplatform. Either way, hide the client behind repositories so the choice stays reversible.
Next step: master the layer underneath Retrofit with OkHttp Interceptors Explained.
Official references
π± Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it βΈ
NotiVaultNotification history: recover dismissed notificationsGet it βΈ
Ready to build real Android applications?
Networking, persistence and offline sync are where real apps get complicated. Practise building a data layer that handles slow networks, failures and caching, not just the happy path.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.