Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:R8

From ReverseEngineering.wiki
Tool
Developer Google (Android Studio / Android Gradle Plugin)
License BSD-3-Clause
Website https://r8.googlesource.com/r8
On this wiki Facts · Code · Notes · Topics

R8 is Google's BSD-3 code shrinker, obfuscator and optimizer for Android; its sibling D8 only converts Java class files to DEX. Both leave a recognisable marker string in the DEX they write.

R8 reads Java class files (and ProGuard-style keep rules), shrinks, optimizes, renames and writes Format:DEX (or class files); D8 is the plain dexer and desugarer without shrinking; L8 desugars the core library. They are the default toolchain of the Android Gradle Plugin, so almost every modern APK went through D8 or R8.

Recognising R8 and D8 output

Each tool adds a marker string to the DEX string pool: ~~ + tool name + a JSON object with its keys in alphabetical order, for example ~~R8{...} or ~~D8{...}. In the R8 sources (Marker.java) the tool names are D8, D8ReOpt, L8, R8, R8Partial, Relocator and R8Assistant, and the JSON keys include version, min-api (deprecated, replaced by min-api-major/min-api-minor), compilation-mode (debug or release), backend, has-checksums, pg-map-id and r8-mode. See Fact:R8/string/R8 marker string in DEX. Searching the raw classes.dex for ~~D8{ or ~~R8{ therefore tells which tool and which minimum API level produced it, and whether the build was shrunk (R8) or not (D8). Release builds with R8 usually have short renamed classes (a.b.c) and, if the developer kept it, a mapping.txt (Format:ProGuard and R8 mapping file).

Unverified: other protectors can strip or forge the marker; its absence does not prove another tool.

See also

Code & repositories

Sources read (not built): R8 at https://r8.googlesource.com/r8 commit db355cd4aa7975f7cad3670207ba55876efdcef9 (src/main/java/com/android/tools/r8/dex/Marker.java, naming/ProguardMapMarkerInfo.java, naming/MapVersion.java); AOSP ART at https://android.googlesource.com/platform/art commit 6484611fd45e69db9f33f98bfd6864014b030ecf for the DEX, VDEX and OAT facts. link_repo accepts only GitHub, GitLab and Codeberg, so these Googlesource repositories are cited in the facts instead.