Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

The release build fails because R8 reports a missing class

ErrorR8: Missing class: java.lang.instrument.ClassFileTransformer

Short answer

R8 found a reference to a class that is not in your app or its libraries. Since AGP 8.0 that fails the build instead of printing a warning. Open the generated missing_rules.txt, decide whether the class is really optional, and add its -dontwarn lines to proguard-rules.pro. If the class should exist, add the dependency.

  • Applies to AGP 8.x, AGP 9, R8, Android Studio
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the file AGP generated next to the mapping output. It lists a -dontwarn rule for every missing class, so you see all of them at once.

    cat app/build/outputs/mapping/release/missing_rules.txt
  2. 2Match what you see, then jump to its fix

    1. 1The class is from java.* or javax.*, or from an annotation or tooling library your dependency only uses at compile timeThe missing class is optional, such as a JVM-only or compile-time-only APIFix
    2. 2The missing class belongs to a library you actually use at runtimeThe class should exist, but a dependency is missingFix
    3. 3The error appears right after an upgrade to AGP 8, with no code changeThe build passed before only because AGP 7 treated these as warningsFix

What does the error look like?

  • R8: Missing class: java.lang.instrument.ClassFileTransformer
  • The release build fails in the R8 minify step, and the build output lists missing classes

Cause 1 of 3

The missing class is optional, such as a JVM-only or compile-time-only API

1Check

R8 reports any class reference it cannot resolve. It is often safe to ignore when a library targets the JVM and the class is of JVM type, or when a dependency uses a compile-time only API.

cat app/build/outputs/mapping/release/missing_rules.txt

2Fix

Copy the rules you accept from missing_rules.txt into proguard-rules.pro. Do not add -ignorewarnings, which hides every warning.

# app/proguard-rules.pro
-dontwarn java.lang.instrument.ClassFileTransformer

3Verify

Build the release variant.

./gradlew :app:assembleRelease

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

The class should exist, but a dependency is missing

1Check

A -dontwarn rule would only silence the build, and the app could crash when that code runs. If the class belongs to a library your code needs, the library is not on the release classpath.

./gradlew :app:dependencies --configuration releaseRuntimeClasspath

2Fix

Add the library that contains the class as a normal dependency, then rebuild before you consider a -dontwarn rule.

dependencies {
    implementation("com.example:library-with-class:1.0.0")
}

3Verify

Rebuild the release variant and check that the class is no longer reported.

./gradlew :app:assembleRelease

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

The build passed before only because AGP 7 treated these as warnings

1Check

In AGP 7.0 missing classes were warnings, and AGP 8.0 made them errors. AGP 8.0 also enforces android.r8.failOnMissingClasses as true, so a false value in gradle.properties is ignored with a warning.

grep -n "failOnMissingClasses" gradle.properties

2Fix

Remove the property if it is there, and handle each missing class with a rule or a dependency as in the causes above.

# gradle.properties: delete this line
# android.r8.failOnMissingClasses=false

3Verify

Run the release build.

./gradlew :app:assembleRelease

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Read missing_rules.txt when you add a library, and accept only rules you understand.
  • Run the release build in CI, so missing classes fail early.
  • Test the minified release on a device before publishing; R8 problems can also show up only at runtime.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.