APK errors

R8: Missing class

Error text

ERROR: R8: Missing class com.example.Foo (referenced from: void com.example.Bar.run())
Missing classes detected while running R8. Please add the missing classes or apply additional keep rules.

Cause

While shrinking, R8 sees a reference to a class that is not there. It happens in release builds when a library's rules are missing.

Step-by-step fix

  1. Open build/outputs/mapping/release/missing_rules.txt. R8 writes the missing rules there.
  2. Copy those lines into proguard-rules.pro.
  3. If the class is truly unused, write -dontwarn. If it is needed, write -keep.
  4. Check whether the library ships its own consumer-rules, and update its version.
  5. Rebuild with ./gradlew assembleRelease and open the app on a phone.

Example commands

# app/build/outputs/mapping/release/missing_rules.txt faylına bax
# proguard-rules.pro
-keep class com.example.Foo { *; }
-dontwarn com.example.Foo
./gradlew assembleRelease

How to prevent it

Build release once after adding each library so the error does not show up late.

Author and license: Nibras Code