Skip to content

fix(android): keep callbacks on non-public base classes from R8 - #8657

Open
ItsChaceD wants to merge 4 commits into
mainfrom
fix/RMET-5521/android-r8-core-rules-cap8
Open

ItsChaceD wants to merge 4 commits into
mainfrom
fix/RMET-5521/android-r8-core-rules-cap8

Conversation

@ItsChaceD

@ItsChaceD ItsChaceD commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a keep rule to core's proguard-rules.pro for @ActivityCallback and @PermissionCallback methods on any Plugin subclass. #8646 keeps the annotation types, but R8 still drops these callbacks when they're declared on a non-public base class.

Tested on 8.5.3 with R8 on and proguard-android-optimize.txt. With #8646 alone, an @ActivityCallback on a package-private base class fails with "There is no ActivityCallback method registered". With this rule it resolves as with R8 off.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

https://outsystemsrd.atlassian.net/browse/RMET-5521

Platforms Affected

  • Android
  • iOS
  • Web

Notes

The Room and Firebase rules from the first version now ship in the plugins that need them, per review. Capacitor 9 gets the same rule in #8658.

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Capacitor apps on AGP 8 and 9 with multiple plugins (including ones with permissions and activity callbacks), no crashes, all is working. Nice!

I'm leaving a non-blocker comment but approving the PR.

Comment thread android/capacitor/proguard-rules.pro Outdated
Comment on lines +31 to +32
-keep class * extends androidx.room.RoomDatabase { void <init>(); }
-keep class * implements com.google.firebase.components.ComponentRegistrar { void <init>(); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you open this file in Android Studio for a plain capacitor app, you'll get Unresolved class name with a red highlight (+ <class member name>, '[' or semicolon expected, got '<init>' for the methods).

While I don't see this as a warning nor build failure nor runtime issue, just the IDE notifying, maybe it's worth clarifying that not all Capacitor apps will have this code by default but these rules are here to prevent certain plugins (like the official capacitor health&fitness plugin or even community plugins) or Firebase setups from having issues?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comment and added #noinspection ShrinkerUnresolvedReference so the warnings disappear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the Room and Firebase lines per Julio’s review, so these warnings are gone too. The plugins that need those rules ship them now.

riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Oct 16, 2026
@ItsChaceD ItsChaceD changed the title fix(android): add R8 keep rules for callbacks and AGP 9 fix(android): keep callbacks on non-public base classes from R8 Oct 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants