AspectK
Compile-time Aspect-Oriented Programming for Kotlin Multiplatform.
AspectK is a Kotlin compiler plugin that injects advice into your functions at compile time, using
the K2 IR transformation API. There is no runtime reflection and no proxy. Declare an @Aspect,
mark its advice with @Before, @After or @Around, and the calls are compiled into every function
that carries the target annotation.

[!WARNING]
AspectK is in alpha. The API can change without notice between releases, and you may run
into bugs. Pin the version you depend on and read the
changelog before upgrading.
[!IMPORTANT]
Use 0.4.2 or later. This is strongly recommended. It is the version
validated on the DuckDuckGo Android browser.
Quick Setup
1. Apply the Gradle plugin
plugins {
id("io.github.mole-labs.aspectk") version "LATEST_VERSION"
}
For Kotlin Multiplatform:
plugins {
kotlin("multiplatform")
id("io.github.mole-labs.aspectk") version "LATEST_VERSION"
}
2. Replace the boilerplate
Before. Cross-cutting concerns are wrapped around the call by hand. Each concern adds one
more level of nesting, and the function name and arguments have to be passed into every wrapper
again:
suspend fun loadProfile(id: String, locale: String): Profile =
traced(name = "loadProfile", args = listOf(id, locale)) {
retrying(name = "loadProfile", times = 3) {
api.loadProfile(id, locale)
}
}
After. The concerns are annotations. Nothing is nested, and nothing is passed by hand:
@Traced
@Retry(times = 3)
suspend fun loadProfile(id: String, locale: String): Profile = api.loadProfile(id, locale)
The wrappers become advice, written once. The join point carries the function name, the
arguments and the annotation values, so nothing has to be passed in:
@Aspect
object CallAspect {
@Around(Traced::class)
suspend fun trace(pjp: SuspendProceedingJoinPoint): Any? { }
@Around(Retry::class)
suspend fun retry(pjp: SuspendProceedingJoinPoint): Any? { }
}
Validated on the DuckDuckGo Android browser
AspectK 0.4.2, resolved from Maven Central, was applied to
DuckDuckGo for Android: an open-source browser with
50M+ downloads on Google Play and 4.8k stars on GitHub. The whole change is public at
oungsi2000/Android (branch aspectk-trial).
Anti-Vibe-Coding
AspectK is built with the help of AI tools, but it is not vibe-coded. The roles are split:
Features
Supported Function Types
Advice is injected during IR transformation, before any platform-specific lowering, so AspectK
sees functions the way you wrote them:
- Class member functions
- Top-level functions
- Extension functions
suspend functions. Injection happens before coroutine lowering, so no continuation parameter shows up in args
inline functions. The advice is part of the body, so it is inlined along with it
Supported Platforms
JVM · Android · JS (IR) · WASM/JS · macOS (arm64, x64) · iOS (arm64, sim, x64) · Linux (arm64, x64) · Windows (x64) · watchOS · tvOS · Android Native
Documentation
Full documentation: https://mole-labs.github.io/aspectk/
License
Copyright 2026 Mole Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https: