Repository navigation
Conversation
R8 full mode removes annotation instances that Capacitor only reads through reflection. PluginHandle.pluginAnnotation and legacyPluginAnnotation are dropped, so getAnnotation() is null at runtime. The null check in getPermissionStates stops that crash, but requestPermissions still NPEs on the null annotation. Keep the annotation interfaces in the consumer ProGuard rules.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8589.
R8 full mode treats annotation types that are only reached through
Class.getAnnotation()/Method.getAnnotation()as unused, then folds the cached annotation inPluginHandleto null.-keepattributes *Annotation*does not stop that. The consumer rules kept the annotated plugin classes, but not the annotation interfaces themselves.#8400 (8.5.2) guards
Bridge.getPermissionStates()socheckPermissions()no longer crashes. On currentmainthe annotation is still null, soPlugin.requestPermissions()takes the legacy@NativePluginbranch and NPEs onlegacyAnnotation.permissions()(Plugin.java:883, inlined intorequestPermissions).This adds
-keep @interfacerules for the annotation types Capacitor reads reflectively (com.getcapacitor.annotation.**,PluginMethod,NativePlugin).NativePluginwas removed onnext, so that one line should be dropped when this is merged forward to Capacitor 9.Verification
Minimal release app,
minifyEnabled true,proguard-android-optimize.txt, R8 full mode, one plugin:The app calls inherited
checkPermissions()thenrequestPermissions(). Same app, three Capacitor builds:checkPermissionsrequestPermissionsgetPermissionStates, process diesmain(includes #8400)missing @CapacitorPlugin annotation for plugin Repro, resolvesundefined{"camera":"prompt"}dexdump -dofPlugin.getPermissionStates()onmainallocates the map, logs the missing-annotation warning, and returns. It never readspermissions(). On this branch the same method loads the kept field and calls the interface:Plugin.requestPermissions()onmainis folded to a null check and theninvoke-virtualon a null reference (the legacy annotation). On this branch it loads both kept fields:usage.txtonmainstill removesPluginHandle.pluginAnnotationandlegacyPluginAnnotation, and the annotation types are renamed (CapacitorPlugin -> v0.b). With this change those fields are no longer removed, andseeds.txtkeepsCapacitorPlugin,Permission,PermissionCallback,ActivityCallback,PluginMethod, andNativePluginunder their original names.