Menu

Kotlin Obfuscator

Renames local variables and parameters, encodes string literals with a matching runtime decoder, and strips comments from your .kt source — entirely in your browser, built for Android projects. Every output is re-checked for structural integrity before it's shown to you.

Obfuscation Studio Free
Ready
Kotlin Source 0 lines • 0 chars
Obfuscated Output 0 lines • 0 chars
Obfuscation Options
All processing runs in your browser. Your code is never uploaded. This obfuscates source — your release APK is already protected separately by R8/ProGuard. See "Does this protect my APK?" in the FAQ below.
Complete Guide to Kotlin Obfuscation

Kotlin obfuscation rewrites readable .kt source into a form that is harder for a human to follow, while preserving the exact runtime behaviour of the original program. This tool uses a hand-written Kotlin tokenizer — aware of string templates, raw strings, and nested block comments — to find identifiers it can safely rename, and performs a structural validation pass on its own output before showing it to you.

Read this before you rely on it: Kotlin compiles to JVM or Dalvik/ART bytecode, which carries its own class and member metadata independent of your original source file. Renaming identifiers in a .kt file does nothing to protect a built APK — a decompiler such as jadx reconstructs readable code straight from the bytecode. Android's release build already runs R8 (or ProGuard) to shrink and obfuscate your compiled code — that's what actually protects a shipped app. This tool protects source text that is shared or exposed as-is — library source, build scripts, snippets — not a compiled artifact.

What is Kotlin Obfuscation?

At the source level, Kotlin obfuscation transforms a .kt file into an equivalent file that is harder to read or copy, without changing what it does once compiled. This is distinct from bytecode-level obfuscation performed by R8/ProGuard (and commercial tools like DexGuard), which operate on the compiled app and actually shrink, inline, and rename at the class-file level — the layer that determines what a decompiled APK looks like.

This tool operates purely at the source level. It's the right fit when the thing you're protecting is the .kt text itself, not a binary you've already built and signed.

Techniques Used by This Tool

Scope-Aware Local Renaming

A brace/paren classification pass distinguishes type bodies (class/interface/object/companion/enum) from function, accessor, init, and lambda bodies — including Kotlin's common parenthesis-less trailing-lambda idiom (run { ... }, apply { ... }). Only identifiers declared inside a function-like body are renamed; primary-constructor val/var properties, data class fields, and companion constants are always left alone.

Template-Reference Protection

Before renaming anything, the tool scans every string for $name and ${expr} references and permanently excludes those identifiers from renaming — so a local variable used inside an interpolated string can never be left dangling with its old name.

String Literal Encoding

Plain double-quoted string literals with no template interpolation are encoded as Base64 bytes XORed with a per-build key, decoded at runtime through a small generated object using java.util.Base64. Raw/triple-quoted strings and anything containing $ are left untouched.

Comment Removal

Handles Kotlin's // line comments and properly nested /* */ block comments (Kotlin allows nesting them, unlike Java/C#), without touching comment-like text inside strings.

How the Tool Works

  1. Tokenize. A hand-written tokenizer splits the source into identifiers, keywords, string/raw-string/char literals (with template-aware brace tracking), numbers, backtick identifiers, operators, and comments.
  2. Scan protected names. A first pass walks the brace-classification stack to collect every type, function, and property name, plus every identifier referenced inside a string template — none of these are ever renamed.
  3. Find rename candidates. A second pass, using the same brace stack plus a parenthesis-kind stack (to tell a parameter list apart from an if/for/when/catch condition), finds local val/var declarations, for-loop and catch variables, and explicit lambda parameters.
  4. Encode strings. Eligible string literal tokens are replaced with calls into a generated decoder object, appended once at the top of the file.
  5. Rename identifiers. Every identifier token matching a candidate is replaced with a short generated name, consistently everywhere that exact name appears.
  6. Reconstruct source. Tokens are re-emitted in order; whitespace and line breaks are preserved by default since Kotlin treats a newline as a statement separator.
  7. Validate structurally. The output is re-tokenized and checked for balanced braces/brackets/parentheses and properly terminated literals. See the note below on what this does and doesn't catch.

Output Validation

A browser cannot run the Kotlin compiler, so this tool cannot fully verify that its output compiles. Instead it re-tokenizes the obfuscated result and confirms every brace, bracket, parenthesis, and string/char/raw-string literal is balanced and correctly terminated — the class of error most likely to be introduced by a renaming/reconstruction bug.

What is not validated: actual Kotlin compilation, type resolution, and runtime behaviour equivalence. Always build and run the obfuscated file in your own project before relying on it, and keep the original source under version control.

What's Safe vs Unsafe to Rename

ConstructRenamed?Reason
Local val/var inside a function/accessor/init bodyYesNot observable outside that body
for (item in items) loop variableYesScoped to the loop body
catch (e: Exception) variableYesScoped to the catch block
Explicit lambda parameters { x, y -> ... }YesScoped to the lambda
Function/constructor parametersOpt-in, off by defaultSafe positionally, but can break named-argument call sites
Primary-constructor val/var propertiesNoPublic API — backs equals(), copy(), destructuring, external access
Class / interface / object / enum / companion namesNoPart of the public type surface
Function and property namesNoMay be called externally, overridden, or used via reflection
Identifiers referenced in a $name/${expr} templateNoTemplate contents aren't rewritten, so the reference must stay valid
Destructuring targets val (a, b) = pairNoSafely tracking the component mapping needs type information this tool doesn't have
Raw / triple-quoted stringsNever encodedTypically multi-line/formatted text, often templated

Use Cases

Library Modules Shared as Source

Internal or open-source-adjacent Kotlin modules that ship as source rather than a compiled .aar benefit from obscured method-body logic while keeping their public API untouched.

Gradle Kotlin DSL Scripts

Hide implementation details of custom build logic (build.gradle.kts, buildSrc) when sharing snippets externally.

Coursework & Interview Exercises

Obscure a reference solution's local logic while keeping its public function signatures intact for grading or discussion.

Pre-Build Source Hardening

One step before your real protection: obfuscate shared source, then let your standard Android release pipeline run R8/ProGuard on the compiled APK/AAB as usual.

Limitations & Legal

  • Not APK protection. The single most important limitation — see the callout above. A shipped Android app is protected by R8/ProGuard (or a commercial tool like DexGuard) at the bytecode level, not by source renaming.
  • Named-argument call sites. If you enable parameter renaming, any caller using foo(paramName = value) against a renamed parameter will fail to compile. This is why parameter renaming defaults to off.
  • Not encryption. String encoding here is reversible by design (the decoder ships right alongside it). Never embed real secrets, API keys, or signing credentials in any Kotlin file.
  • Destructuring declarations. val (a, b) = pair and destructured lambda parameters { (a, b) -> ... } are left untouched rather than risk corrupting the component mapping.
  • Local (nested) functions. A function declared inside another function keeps its own name, though its parameters are still renamable when the option is on.
  • Legal. Only obfuscate code you own or have rights to modify. Do not obfuscate open-source code in ways that violate its license.

Related Obfuscators

Frequently Asked Questions

What is a Kotlin obfuscator?
A Kotlin obfuscator rewrites readable .kt source into a form that is harder for a human to follow while preserving identical runtime behavior. Typical transformations include renaming local variables and parameters, encoding string literals, and removing comments.
Does this protect my APK?
No, and this is the most important thing to understand. This tool rewrites your .kt source text before you build. Once compiled to JVM/Dalvik bytecode and packaged, a decompiler such as jadx or JD-GUI reconstructs readable Kotlin/Java directly from the bytecode, independent of how your original source was named. Android's own release build pipeline already runs R8 (or ProGuard) to shrink, optimize, and obfuscate your compiled code — that is what actually protects a shipped APK or AAB, not source-level renaming.
Then what is this tool actually useful for?
Protecting source-level readability in contexts where the .kt file itself is what gets shared or exposed: library modules distributed as source, Gradle Kotlin DSL build scripts, internal tooling, teaching or interview exercises, or reducing casual copy-paste reuse of logic shared as plain text — as a complement to, not a replacement for, R8/ProGuard on your actual release build.
Is my code uploaded to your server?
No. The obfuscator runs entirely as JavaScript inside your browser. Your Kotlin source code never leaves your device.
Does obfuscation break my code?
The tool only renames identifiers it can determine are purely local — variables, catch/for-loop variables, and lambda parameters declared and used strictly inside a function body — and never touches class, interface, object, enum, function, or property names. It also protects any identifier referenced inside a string template ($name or ${expr}) so a rename can never leave a stale reference behind. A structural validation pass checks brace/bracket/quote balance after transformation. Reflection, named-argument call sites, and destructured declarations are documented limitations above.
Will renaming parameters break named-argument calls?
It can. Kotlin lets callers use foo(paramName = value), and this tool cannot reliably find every call site that names a given parameter. Parameter renaming is therefore off by default — turn it on only for files where you've checked (or don't use) named arguments against the parameters being renamed.
Does it work with data classes?
Yes, and safely: primary-constructor properties declared with val or var (the fields of a data class) are always treated as public API and are never renamed, since renaming them would break equals(), copy(), destructuring, and external access.
Does it work with Jetpack Compose?
Yes for the Kotlin logic. @Composable functions, their parameters, and locals inside them are handled the same as any other function. As with any Kotlin file, parameter renaming is off by default because Compose code commonly uses named arguments for readability.
Does it handle coroutines and suspend functions?
Yes. suspend is just a modifier before fun and doesn't change how parameters or locals are detected. Lambda parameters inside coroutine builders (launch, async, withContext) follow the same lambda-parameter rules as any other lambda.
Which Kotlin versions are supported?
The tokenizer recognizes modern Kotlin syntax including data/sealed classes, companion objects, extension functions, string templates, raw (triple-quoted) strings, nested block comments, and numeric literals with underscore separators. Destructuring declarations (val (a, b) = pair) are intentionally left unrenamed to avoid corrupting the pattern.
Can obfuscated Kotlin source be reversed?
Source-level obfuscation is a deterrent, not encryption. Anyone with the obfuscated .kt file can still compile and run it. Never embed real secrets, API keys, or signing credentials in any Kotlin file, obfuscated or not — use the Android Keystore or a secrets manager instead.
Will it break public classes, functions, or properties?
No. This tool deliberately never renames class, interface, object, enum, companion object, function, or property names — including primary-constructor val/var properties — so your public API surface stays exactly as written.
What does string encoding do?
Plain double-quoted string literals with no $ template are Base64-encoded and XORed with a per-build key, then wrapped in a call to a small generated decoder object using java.util.Base64. Raw/triple-quoted strings and any string containing template interpolation are left untouched to avoid corrupting embedded expressions.
Does the decoder work on older Android API levels?
java.util.Base64 requires API 26+ (Android 8.0), or API level desugaring enabled in your Gradle build for lower minSdk. If you target an older API without desugaring, swap the decoder to android.util.Base64.decode(s, android.util.Base64.DEFAULT) instead.
Can I use this commercially?
Yes. You may obfuscate any code you own or have rights to modify and distribute the output under your own license.
What identifiers are safe to rename?
Local val/var declarations inside a function, accessor, init block, or lambda body; for-loop and catch-block variables; and explicit lambda parameters — provided none of them are referenced inside a string template elsewhere. Types, functions, and properties (including primary-constructor properties) are never touched.
Will it break destructuring declarations?
The tool intentionally does not rename names inside a destructuring pattern, such as val (id, name) = pair or a lambda like { (a, b) -> a + b }, since safely tracking the component mapping is unreliable without full type information.
Does it support Kotlin Multiplatform (KMP)?
It operates on plain .kt source, so it works on shared KMP modules the same way it works on any other Kotlin file. expect/actual declarations are treated as ordinary function/property declarations and are never renamed.
How is the output validated?
This tool cannot run the Kotlin compiler in the browser, so it performs a structural validation pass: it re-tokenizes the obfuscated output and checks that every brace, bracket, parenthesis, and string/char/raw-string literal is correctly balanced and terminated. This catches reconstruction bugs but is not a substitute for building the result yourself, which you should always do before shipping.
Can obfuscation be detected?
Yes. A reviewer opening the file will immediately see short renamed identifiers and a decoder helper object. This tool is for reducing casual readability of shared source, not for hiding that obfuscation occurred.

Conclusion

Source-level Kotlin obfuscation is a narrow, honest tool: it makes a .kt file less readable without changing what it does, is careful about Kotlin-specific traps (primary-constructor properties, string templates, named arguments, destructuring), and is upfront that it is not a substitute for R8/ProGuard protecting your compiled Android app. Combine it with proper secret management (never in source, obfuscated or not) and your standard release build pipeline for anything you actually ship.