/delphi-android-r8:delphi-android-r8from delphi-android-r8
Runs R8/ProGuard inside Delphi 13.x FMX Android builds to shrink, optimize, and obfuscate DEX code for Google Play compliance. Fixes low DEX optimization warnings, large DEX files, and missing system JARs that cause crashes.
Ships in delphi-android-r8. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Delphi 13.x never runs R8: it dexes with D8 and merges, so Play sees ~0 % shrinking/optimization/obfuscation
and a large DEX. scripts/DX.R8.targets hooks in after BuildClassesDex, rebuilds the DEX with R8 from the
original JARs (keep rules generated automatically), and puts mapping.txt + r8.json into the AAB before
Delphi signs it. Reference result: DEX 15.24 MB -> 5.49 MB (decimal), Play reports ~82 % on all three values.
verify can still crash. The device/emulator start test (step 7) is mandatory on every R8 build.-keep class com.google.** { *; }).$(JAVA_TOOL) is used in the build), Python 3.10+ (py -3 on Windows; override with /p:DX_R8_Python=...).tools/delphi-r8/r8/r8.jar: run scripts/fetch_r8.ps1 (SHA-256 pinned). Do NOT use
Delphi's bundled R8 (cmdline-tools 16.0 = 8.6.17): it fails with Unknown option: --build-metadata-output.
Add r8/ to .gitignore (55 MB).bundletool 1.18+, adb, a device or emulator (API 31 x86_64 Google APIs
image works; it runs arm64 libs via translation), optionally android analyze (Android CLI) for Play's numbers.Build the AAB once without R8 and check it:
python scripts/dx_r8.py check-dex --aab MyApp.aab
It must list com/embarcadero/firemonkey/FMXNativeActivity. If it is missing or the DEX is only a few hundred KB,
the .dproj has no <EnabledSysJars> for Android64: Delphi 13 then packs no system JARs (fmx, androidx,
play-services) and the app cannot start. Fix: enable the needed libraries under Project > Libraries for
Android64 (or copy EnabledSysJars/DisabledSysJars from a working Delphi 13 sample), rebuild, re-check.
Add --require <class> for classes your app must have (e.g. com.google.android.gms.ads.MobileAds).
scripts/ to the app repo as tools/delphi-r8/ (DX.R8.targets, dx_r8.py, delphi-base-rules.pro, fetch_r8.*, smoke_test.sh)..dproj, right before </Project> (adjust the relative path):
<Import Project="..\tools\delphi-r8\DX.R8.targets" Condition="Exists('..\tools\delphi-r8\DX.R8.targets')" />
tools/delphi-r8/fetch_r8.ps1.r8-rules.pro next to the .dproj (empty is the normal case).The hook is active only for Android64 + AppStore and is on by default; /p:DX_R8=false switches it off.
From a RAD Studio command prompt (rsvars.bat), same config both times:
msbuild MyApp.dproj /t:Build;Deploy /p:Config=Release /p:Platform=Android64 /p:BT_BuildType=AppStore /p:DX_R8=false
msbuild MyApp.dproj /t:Build;Deploy /p:Config=Release /p:Platform=Android64 /p:BT_BuildType=AppStore
Keep both AABs. The R8 log line must show a non-zero number of consumer rule files when the app uses AARs
(DX.R8: 94 JARs, 535 JNI classes, 9 embedded and 6 consumer rule files, 1 DEX file(s)). Work files land in
$(APK_OutputDir)r8\ (r8.log, generated-rules.pro, consumer-*.pro, jni-classes.txt, mapping.txt, r8.json).
If you put the msbuild call into a .cmd file and pass lists with %3B, write %%3B.
android analyze before.aab android analyze after.aab
java -jar bundletool.jar get-size total --apks=<split .apks> --device-spec=assets/arm64.json
Expect: DEX size down 60-70 %, "R8 enabled", shrinking/optimization/obfuscation each well above 25 %, and the
"low rate of dex optimization" warning gone. Without r8.json Play only estimates obfuscation. Download size
drops less (~20 %) because the native lib<App>.so dominates Delphi apps.
python tools/delphi-r8/dx_r8.py verify --jni <APK_OutputDir>/r8/jni-classes.txt --aab after.aab
Must be N/N. Any MISSING: line = R8 renamed or removed a class Delphi calls by name. This catches only JNI
names from the .so, not reflection inside Java libraries.
Keep mapping.txt per version code (Play gets it via BUNDLE-METADATA; you need it for stack traces elsewhere).
tools/delphi-r8/smoke_test.sh after.aab com.example.myapp
(universal APK via bundletool with a debug key, adb install, launch, wait ~30 s, logcat grep for
ClassNotFound|NoClassDefFound|NoSuchMethod|NoSuchField|UnsatisfiedLink|JNI DETECTED ERROR|FATAL EXCEPTION.)
Run it for the non-R8 build too, so you know which log lines are pre-existing. Then click through every
feature that loads Java code lazily: ads (banner, interstitial, rewarded, app open, with test ad units),
consent form (UMP, debug geography EEA), "Ad privacy choices", in-app purchase, push, maps, share, camera/gallery,
review prompt, deep links, rotate, background and resume. Reflection crashes appear seconds later on worker
threads (reference: UMP crashed after ~6 s in "Google consent worker #1").
zze in d2.m1 point
to protobuf-lite/reflection in a Google SDK).consumer-*.pro in the work dir must contain that AAR's
proguard.txt. If not, the AAR is not in @(AarReference) - fix the reference, not the rules.r8-rules.pro
(e.g. -keepclassmembers class * extends com.vendor.internal.Foo { <fields>; }), rebuild, re-run steps 4-7.Before/after table (DEX bytes, files, the three Play percentages, download size), verify result, smoke-test result incl. what was NOT exercised, any rules you added. Ask for the OK before merging to the release branch or uploading anything.
references/pitfalls.md - every trap found so far, with symptoms and fixes. Read before debugging.references/reference-numbers.md - full measurements of the reference app (A/B/B2/C).references/how-it-works.md - Delphi 13 DEX pipeline, hook points, keep-rule generation, post-aab route.assets/AGENTS-snippet.md - short pointer to paste into an app repo's AGENTS.md / CLAUDE.md.assets/arm64.json - device spec for bundletool get-size.assets/AGENTS-snippet.md (opens in a new tab)assets/arm64.json (opens in a new tab)references/how-it-works.md (opens in a new tab)references/pitfalls.md (opens in a new tab)references/reference-numbers.md (opens in a new tab)scripts/DX.R8.targets (opens in a new tab)scripts/delphi-base-rules.pro (opens in a new tab)scripts/dx_r8.py (opens in a new tab)scripts/fetch_r8.ps1 (opens in a new tab)scripts/fetch_r8.sh (opens in a new tab)scripts/smoke_test.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub omonien/delphistandards --plugin delphi-android-r8Other plugins' skills for the same job