The release build fails because R8 reports a missing class
R8: Missing class: java.lang.instrument.ClassFileTransformerShort 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.
Fix it fast
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.txt2Match what you see, then jump to its fix
- 1
The 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
The missing class belongs to a library you actually use at runtimeThe class should exist, but a dependency is missingFix - 3
The error appears right after an upgrade to AGP 8, with no code changeThe build passed before only because AGP 7 treated these as warningsFix
- 1
What does the error look like?
R8: Missing class: java.lang.instrument.ClassFileTransformerThe 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.txt2Fix
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.ClassFileTransformer3Verify
Build the release variant.
./gradlew :app:assembleReleaseConfirmed by developer.android.com
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 releaseRuntimeClasspath2Fix
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:assembleReleaseConfirmed by developer.android.com
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.properties2Fix
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=false3Verify
Run the release build.
./gradlew :app:assembleReleaseConfirmed by developer.android.com
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 fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix