Release build fails: R8 cannot find a Facebook Nullsafe class
ERROR: R8: Missing class com.facebook.infer.annotation.Nullsafe$Mode (referenced from: ... com.facebook.ads.NativeAdBase ...)Short answer
R8 found a reference to a class that is not in your app or its libraries, and since Android Gradle plugin 8.0 that stops the build. The Facebook SDK refers to an annotation class it does not ship. Add the -dontwarn lines from the generated missing_rules.txt to your ProGuard file, and make sure that file is actually listed for the release build.
Fix it fast
1Find out which cause you have
Run the release build and open the file the error names. It lists the exact -dontwarn lines R8 wants, so you do not have to guess class names.
./gradlew :app:assembleRelease cat app/build/outputs/mapping/release/missing_rules.txt2Match what you see, then jump to its fix
- 1
Missing class com.facebook.infer.annotation.Nullsafe$Mode appears only when minify is enabled for the build typeR8 treats a missing class as an error and the rule is not in your ProGuard fileFix - 2
The -dontwarn line is in the file and the same error still appearsproguard-rules.pro exists but the release build type does not use itFix
- 1
What does the error look like?
ERROR: R8: Missing class com.facebook.infer.annotation.Nullsafe$Mode (referenced from: ... com.facebook.ads.NativeAdBase ...)R8: Missing class ... (AGP 7.0 warning form)
Cause 1 of 2
R8 treats a missing class as an error and the rule is not in your ProGuard file
1Check
Since AGP 8.0 the flag android.r8.failOnMissingClasses is always true and cannot be switched off. A class the SDK refers to but nobody ships therefore fails the build. Open proguard-rules.pro and look for a matching -dontwarn line.
grep -n "dontwarn" app/proguard-rules.pro2Fix
Copy the lines from missing_rules.txt into the file. For this error the line is for the annotation package the message names. Do not set -ignorewarnings; it hides every missing class, not just this one.
# app/proguard-rules.pro
-dontwarn com.facebook.infer.annotation.**3Verify
Build the release variant again. The R8 step should pass and no new Missing class lines appear.
./gradlew :app:assembleReleaseConfirmed by developer.android.com
Cause 2 of 2
proguard-rules.pro exists but the release build type does not use it
1Check
Rules only count when the file is listed under proguardFiles for the build type that has minify on. A file that is not listed is silently unused.
grep -n -A6 "release" app/build.gradle.kts2Fix
List your rules file next to the default optimize file in the release block (Kotlin DSL shown). On AGP 9.3 or newer with the optimization block, put rules in a file ending in .keep under src/main/keepRules instead.
android {
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}3Verify
Run the release build; the merged rules report (the configuration.txt file) should contain your dontwarn line.
./gradlew :app:assembleRelease
grep -n "infer.annotation" app/build/outputs/mapping/configuration.txtConfirmed by developer.android.com
How do I stop it coming back?
- Run a release build in CI on every change that touches a dependency, not only a debug build.
- After adding an ad or analytics SDK, build with minify on the same day and read missing_rules.txt.
- Keep -dontwarn lines narrow (one package) so a real missing dependency elsewhere is still reported.
- Never set -ignorewarnings to get past this error.
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
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix