Format:Kotlin metadata
| Developer | JetBrains |
|---|---|
| License | Apache-2.0 |
| On this wiki | Facts · Code · Notes · Topics |
Every class file produced by the Kotlin compiler carries a runtime-visible kotlin.Metadata annotation with the short-named fields k (kind), mv (metadata version), bv, d1 (protobuf-encoded data as strings), d2 (string table), xs, pn and xi (flags); decoding d1/d2 restores Kotlin signatures that the JVM bytecode lost.
The annotation
From libraries/stdlib/jvm/runtime/kotlin/Metadata.kt in JetBrains/kotlin. The annotation kotlin.Metadata (Retention RUNTIME, target CLASS, since Kotlin 1.3) sits on every class file Kotlin writes. Its parameters have very short JVM names on purpose:
| JVM name | Kotlin name | Meaning |
|---|---|---|
k |
kind | 1 class, 2 file facade, 3 synthetic class, 4 multi-file class facade, 5 multi-file class part; other values = not a Kotlin class |
mv |
metadataVersion | int array, e.g. [1, 9, 0] or [2, 1, 0] |
bv |
bytecodeVersion | deprecated, default [1, 0, 3] |
d1 |
data1 | metadata in a custom format (string array holding a protobuf message for classes and file facades) |
d2 |
data2 | string table: names that occur in the metadata, indexed from d1, so constant-pool strings are reused |
xs |
extraString | for a multi-file part, the internal name of the facade |
pn |
packageName | Kotlin package when it differs from the JVM package (@JvmPackageName) |
xi |
extraInt | flag bits (see below) |
xi bits: 0 multi-file facade/part compiled with -Xmultifile-parts-inherit; 1 compiled by a pre-release compiler; 2 compiled script (.kts); 3 strict metadata version semantics; 4 JVM IR backend (Kotlin 1.4+); 5 stable metadata and ABI; 6 K2 frontend (only before metadata version 2.0.0); 7 used in an inline function scope; 8-10 visibility of a synthetic class (from metadata 2.5.0).
Why it matters when reversing
- Presence of
Lkotlin/Metadata;in a class (or in the DEX annotation set) proves a Kotlin origin even after renaming;mvidentifies the compiler generation (1.x versus 2.x). - The JVM bytecode erases nullability, default arguments, extension receivers, data/sealed/inline class status and property-vs-method; the d1 protobuf restores them. Tools that read it: the
kotlin-metadata-jvmlibrary and kotlinx-metadata (Unverified: library names are from general knowledge), and several decompilers use it to recover signatures. - Obfuscators (R8, ProGuard) usually keep kotlin.Metadata so reflection works, but when shrinking they rewrite d2 together with renamed classes; if the annotation is stripped, Kotlin reflection fails (Unverified).
- Files named
META-INF/<module>.kotlin_modulein JARs list top-level functions and facades per package (Unverified here: format not read).
Companion artefacts: Kotlin generates helper names such as $DefaultImpls, $WhenMappings, Intrinsics.checkNotNullParameter calls (Unverified: from general knowledge), useful as fingerprints in decompiled output. Container formats: Format:JAR, Format:DEX.
Code & repositories
- https://github.com/JetBrains/kotlin @
5827df9172f0a7cee5eda8dac6439a35100a6ac7· license: Apache-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)
Kotlin compiler repository; libraries/stdlib/jvm/runtime/kotlin/Metadata.kt documents the kotlin.Metadata annotation fields and flag bits.
Tested on: source read, not run: Read Metadata.kt at this commit (October 2026). · checked 2026-10-18; last activity 2026-10-18; Note: the latest release ships binaries; the wiki links only the source, never the binaries