ERROR: Missing classes detected while running R8

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Error:-

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in C:\Flutter app\wizbrand\build\app\outputs\mapping\release\missing_rules.txt.
ERROR: R8: Missing class com.google.errorprone.annotations.CanIgnoreReturnValue (referenced from: com.google.crypto.tink.KeysetManager com.google.crypto.tink.KeysetManager.add(com.google.crypto.tink.KeyTemplate) and 52 other contexts)
Missing class com.google.errorprone.annotations.CheckReturnValue (referenced from: com.google.crypto.tink.InsecureSecretKeyAccess and 1 other context)
Missing class com.google.errorprone.annotations.Immutable (referenced from: com.google.crypto.tink.InsecureSecretKeyAccess and 40 other contexts)
Missing class com.google.errorprone.annotations.RestrictedApi (referenced from: com.google.crypto.tink.aead.AesEaxKey$Builder com.google.crypto.tink.aead.AesEaxKey.builder() and 6 other contexts)
Missing class javax.annotation.Nullable (referenced from: java.lang.Object com.google.crypto.tink.PrimitiveSet$Entry.fullPrimitive and 86 other contexts)
Missing class javax.annotation.concurrent.GuardedBy (referenced from: com.google.crypto.tink.proto.Keyset$Builder com.google.crypto.tink.KeysetManager.keysetBuilder and 3 other contexts)

Solution:-

If your project does not include a proguard-rules.pro file, you can create one and configure it in your Gradle build settings. Here’s how you can proceed:

1. Create proguard-rules.pro File

Create a new file named proguard-rules.pro in your project directory under the android/app/ folder.

  • File Path: android/app/proguard-rules.pro

2. Add the Missing Rules

Copy the following rules into the newly created proguard-rules.pro file:

# Suppress warnings for missing annotations and classes
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn com.google.errorprone.annotations.RestrictedApi
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.concurrent.GuardedBy

3. Enable ProGuard in build.gradle

Modify the android/app/build.gradle file to include your proguard-rules.pro configuration:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
  • minifyEnabled true: Enables R8/ProGuard to shrink and obfuscate your code.
  • shrinkResources true: Removes unused resources during the build process.

4. Rebuild the Project

After adding the proguard-rules.pro file and enabling ProGuard, clean and rebuild your Flutter project:

flutter clean
flutter pub get
flutter build apk --target-platform android-arm,android-arm64 --split-per-abi

5. Debug Build Failures

If the issue persists, try disabling code shrinking temporarily to pinpoint the problem:

android {
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
        }
    }
}

Rebuild the APK to see if it works without the R8 code shrinking enabled.

Additional Notes:

  • If you’re using Flutter plugins or dependencies that rely on native code, ensure that they are updated to the latest version.
  • Missing annotations might also occur due to outdated dependencies. Update your Gradle and SDK versions as necessary.

Senior Software Development Engineer at Cotocus

Related Posts

Ship Open-Testing Build to Production on Google Play (Flutter)

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now What…

Read More

Flutter + Paytm: Fixing “Namespace not specified”, missing paytm package, and AGP 8 build errors (Complete Guide)

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now 0)…

Read More

Fixing “FileSystemException: The process cannot access the file because it is being used by another process” in Flutter

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Problem…

Read More

Flutter clean: Failed to remove build. A program may still be using a file in the directory or the directory itself.

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Error:-…

Read More

Flutter Tutorial: How to Open a Website in the Browser

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Want…

Read More

The Ultimate Guide to Designing a Stunning UI for Your App (Built for Digital Marketers & SEO Engineers)

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Who…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments