Skip to main content

Fix DEX Code Optimization Below Threshold (Capacitor)

Play Console warns DEX code optimization is below our threshold. Enable R8 minify and shrink on Capacitor Android release builds, upload mapping, and ship a new AAB.

Capgo blog graphic: Fix DEX code optimization below threshold in Capacitor apps, with Android vitals and R8 minify on release

Quick answer: When Play Console says DEX code optimization is below our threshold, Google scored shrinking, optimization, or obfuscation on your DEX too low, often because the Capacitor Android release build still has R8 off. Turn on R8 minify and resource shrink, use proguard-android-optimize.txt, keep Capacitor plugins with the shipped consumer rules, rebuild a release AAB, and upload it with mapping.txt. JavaScript minification does not count toward this warning.

// android/app/build.gradle (Groovy)
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
// android/app/build.gradle.kts
buildTypes {
    getByName("release") {
        isMinifyEnabled = true
        isShrinkResources = true
        proguardFiles(
            getDefaultProguardFile("proguard-android-optimize.txt"),
            "proguard-rules.pro"
        )
    }
}

The vitals card often shows low obfuscation percentage alongside optimization and shrinking:

Google Play Console Android vitals warning showing obfuscation at 3 percent, below the 25 percent app optimization threshold, with a February 2027 fix date

Policy and measurement detail: Play Console technical quality requirements, DEX code optimization, and enable app optimization with R8.

What Google Play is measuring

Google Play inspects compiled Java and Kotlin DEX inside your App Bundle: Capacitor, plugins, and AndroidX. From February 2027, apps with more than 10 MB of DEX must meet published floors on all three metrics (games use a higher DEX size gate). Play does not publish a separate numeric threshold for every app size; see the official policy link above for enforcement timing and eligibility.

Metric What it means Typical Capacitor cause of a low score
Obfuscation Class, field, and method names shortened minifyEnabled is still false
Optimization R8 inlines, merges, and rewrites bytecode Default proguard-android.txt includes -dontoptimize
Shrinking Unused classes and methods removed Code shrinking never turned on

On recent Android Gradle Plugin versions, Play can read r8.json inside the bundle. Otherwise it uses mapping.txt or DEX heuristics. A release built without R8 often has almost no mapping file, so readable names remain and Play reports a few percent obfuscation.

Step 1: Turn R8 on for release

The Capacitor template still ships release builds without R8:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

That default lives in android-template/app/build.gradle. Debug builds should stay unminified. Release builds you upload to Play should not.

Three details matter:

  1. minifyEnabled true runs R8 (shrink, obfuscate, optimize).
  2. shrinkResources true removes unused Android resources and requires minification.
  3. Use proguard-android-optimize.txt. Plain proguard-android.txt ships -dontoptimize, which blocks optimization. See Capacitor Plugin AGP 9 Build Error Fix if a plugin still references the old file.

Do not set minifyEnabled true on debug. Keep local runs fast and stack traces readable.

Step 2: Do not disable R8 full mode

Open android/gradle.properties and remove this line if it exists:

android.enableR8.fullMode=false

AGP 8+ enables full mode by default. That legacy flag caps optimization.

Search android/app/proguard-rules.pro for:

-dontobfuscate
-dontoptimize
-dontshrink
-keep class ** { *; }

Those rules keep scores low even after you enable R8.

Cannot use optimization.enable=true without android.r8.gradual.support

On Android Gradle Plugin 9.0 and later, Google added an optimization { } block with enable = true and an experimental packageScope path to optimize named packages first (optimize specified packages).

Add this line in the project gradle.properties file (not module level) when Gradle asks for gradual R8 support:

android.r8.gradual.support=true

Match the fix to the exact error text:

  1. Cannot use optimization.enable=true without setting android.r8.gradual.support flag. Some AGP versions require the flag when you turn on optimization { enable = true } even without packageScope. Adding android.r8.gradual.support=true is enough. You do not have to configure packageScope.
  2. Cannot use optimization.packageScope without setting android.r8.gradual.support flag. You set packageScope inside optimization { }. Add the same gradle.properties flag. packageScope also requires R8 full mode (remove android.enableR8.fullMode=false).

Capacitor recommendation: Most Capacitor apps should not start with packageScope. Use the legacy release block at the top of this post (minifyEnabled / isMinifyEnabled plus shrinkResources). That satisfies Play DEX optimization without the gradual DSL.

If you already adopted optimization { enable = true } from an AGP 9.3+ template, either add the flag and follow the Android doc for your AGP version, or revert to isMinifyEnabled = true and isShrinkResources = true with proguard-android-optimize.txt. The optimization.enable property itself was added in AGP 8.13; documented packageScope gradual mode starts at AGP 9.0+.

Step 3: Keep Capacitor plugins, not the whole app

R8 respects reflection metadata. Capacitor discovers plugins by annotation, so they need keep rules. You usually do not add them yourself. Since Capacitor 3.2.3, @capacitor/android ships consumer ProGuard rules for @CapacitorPlugin, @PluginMethod, and com.getcapacitor.Plugin.

Add rules in android/app/proguard-rules.pro only for a reproducible release crash:

# Good: one misbehaving plugin package
-keep class com.mycompany.myplugin.** { *; }

# Bad: this tanks obfuscation and shrinking
-keep class com.getcapacitor.** { *; }
-keep class ** { *; }

Official notes: Using ProGuard.

Step 4: Build a real release bundle

Play grades what you upload, not a debug APK. Bump versionCode in android/app/build.gradle or android/app/build.gradle.kts (defaultConfig { versionCode = ... }) so the new bundle is higher than the last Play upload (version your app). From the project root:

bun run build   # or: npm run build
bunx cap sync android   # or: npx cap sync android
cd android
./gradlew bundleRelease

For signing without Android Studio, see Build and Install Release APK Without Android Studio. You can generate or inspect an upload keystore with the Android keystore generator.

Install a release APK (./gradlew assembleRelease) and exercise native plugins. R8 issues rarely appear in debug cap run sessions.

After bundleRelease, confirm R8 ran:

  • app/build/outputs/mapping/release/mapping.txt
  • app/build/outputs/mapping/release/configuration.txt
  • On supported AGP versions, r8.json inside the .aab

If mapping.txt is missing, verify minifyEnabled true on release and that keep rules do not include -dontobfuscate.

Step 5: Upload mapping and re-check Play

Obfuscated crashes need the mapping file for each version.

  1. Play Console: Test and release → App bundle explorer → your version → Downloads → Assets. Upload mapping.txt if it is not already attached (deobfuscation file).
  2. Firebase Crashlytics / Sentry: upload the same mapping from CI.

Open App bundle explorer for DEX size plus obfuscation, optimization, and shrinking percentages. Monitor and improve → Android vitals updates after Play analyzes the version you shipped.

Troubleshooting

App crashes after enabling R8 (login, plugins, reflection)

Symptoms often surface only on a release install (search queries such as R8 APK login usually mean auth broke under obfuscation). Steps:

  1. Reproduce on assembleRelease, not debug.
  2. Read the stack trace. With mapping uploaded, Play and crash tools deobfuscate it.
  3. Add the smallest -keep rule for the package that crashed. Remove app-wide keeps.
  4. Update plugins that ship no consumer rules. Prefer maintained plugins from the Capgo plugin directory.

Broad keep rules still yield a low obfuscation percentage

Use R8 Configuration Analyzer on AGP 9.3+ after assembleRelease. On older AGP, use APK Analyzer with mapping.txt and Play’s bundle explorer. App-level -keep class com.foo.** { *; } is a common culprit.

Play still shows the warning on an old version

Upload a new .aab built with R8 on. Internal testing is enough to refresh bundle explorer metrics for that artifact. Confirm CI did not deploy an unsigned debug artifact.

What this does not replace

  • JavaScript minification in Vite does not change DEX scores.
  • Capgo live updates refresh the web layer only. DEX optimization needs a native store upload once R8 is enabled in the binary.
  • 16 KB page size is a separate requirement. See Android 16 KB page size.

For CI, ensure workflows run bundleRelease or assembleRelease, not debug. See Automatic Capacitor Android build with GitHub Actions.

Frequently asked questions

What does DEX code optimization is below our threshold mean?

Play measured your uploaded DEX and found shrinking, optimization, or obfuscation below the policy floor described in Google Play technical quality requirements. Capacitor apps often ship with R8 disabled on release, so all three scores stay in single digits until you enable minify with optimize defaults.

What is obfuscation percentage on Google Play?

It is the share of app DEX code that R8 (or another shrinker) renamed. Optimization percentage and shrinking percentage are separate lines in App bundle explorer. None of the three is a substitute for the others.

How do I fix DEX code optimisation below threshold in Capacitor?

Enable R8 on the release build type, use proguard-android-optimize.txt, run ./gradlew bundleRelease, upload mapping.txt, and publish the new AAB. British spelling optimisation and American optimization refer to the same Play metric.

Why does Gradle require android.r8.gradual.support?

Gradle may require android.r8.gradual.support=true in project gradle.properties when you use optimization.enable=true, when you set packageScope, or both, depending on AGP version and the exact error string. Capacitor teams can avoid the new DSL by using isMinifyEnabled / minifyEnabled on release instead.

Why does my Capacitor app crash after I enable R8?

Reflection-heavy plugins without keep rules are the usual cause. Test release, tighten keeps, update the plugin. Do not disable R8 to pass Play; fix rules instead.

How do I verify obfuscation percentage improved?

Compare App bundle explorer before and after your optimized upload. Locally, confirm mapping.txt is non-empty and matches the version code you shipped.

Checklist

  • release { minifyEnabled true; shrinkResources true }
  • proguard-android-optimize.txt (not proguard-android.txt)
  • No -dontobfuscate / -dontoptimize / app-wide -keep class **
  • Capacitor 3.2.3+ so plugin consumer rules apply
  • Release build produces mapping.txt
  • Native plugins tested on a release install
  • New .aab uploaded; mapping attached in App bundle explorer
  • Obfuscation, optimization, and shrinking each meet Play floors for your DEX size

Keep going from Fix DEX Code Optimization Below Threshold (Capacitor)

If you are using Fix DEX Code Optimization Below Threshold (Capacitor) to plan Android store releases, connect it with Capgo Native Builds for release App Bundles, Capgo CI/CD for the upload pipeline, CI/CD Integration for implementation detail, Automatic Capacitor Android build with GitHub actions for self-hosted pipelines, and Capgo Consulting if a plugin breaks after R8 is enabled.

Live updates for Capacitor apps

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

Latest from our Blog

Capgo gives you the best insights you need to create a truly professional mobile app.