Maaz Zindani

Loading the index…

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

Release build fails: R8 cannot find a Facebook Nullsafe class

ErrorERROR: 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.

  • Applies to Android Gradle plugin 8.x and 9.x, Gradle 8.x and 9.x, Audience Network SDK 6.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.txt
  2. 2Match what you see, then jump to its fix

    1. 1Missing 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. 2The -dontwarn line is in the file and the same error still appearsproguard-rules.pro exists but the release build type does not use itFix

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.pro

2Fix

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:assembleRelease

Confirmed by developer.android.com

Did this fix it?

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.kts

2Fix

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.txt

Confirmed by developer.android.com

Did this fix it?

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

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 fix

Mobile 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

Next step

Want this handled for good?

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