Ship consumer-rules.pro so JS bridge methods survive R8 (closes #1072)#1088
Ship consumer-rules.pro so JS bridge methods survive R8 (closes #1072)#1088jim-daf wants to merge 2 commits intoJustson:androidxfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR packages Proguard/R8 consumer rules with the agentweb-core AAR so that consumer apps don’t lose @JavascriptInterface bridge methods when minification is enabled (fixing the crash reported in #1072).
Changes:
- Add
consumerProguardFiles 'consumer-rules.pro'to theagentweb-coreAndroid library configuration. - Introduce
agentweb-core/consumer-rules.prowith keep rules for@JavascriptInterfacemethods and AgentWeb classes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
agentweb-core/consumer-rules.pro |
Adds consumer R8/Proguard rules intended to preserve JS bridge methods and AgentWeb classes in consuming apps. |
agentweb-core/build.gradle |
Ensures the consumer rules file is shipped with the published AAR via consumerProguardFiles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
| testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' | ||
| // Issue #1072: ship Proguard/R8 rules so consumer apps do not have to | ||
| // re-declare the @JavascriptInterface keep rule themselves. | ||
| consumerProguardFiles 'consumer-rules.pro' |
There was a problem hiding this comment.
testInstrumentationRunner is assigned twice; the second line overrides the first, which is confusing and makes the support runner line effectively dead. Consider removing the unused assignment to keep defaultConfig unambiguous.
| -keepclassmembers class * { | ||
| @android.webkit.JavascriptInterface <methods>; | ||
| } |
There was a problem hiding this comment.
-keepclassmembers will keep the annotated methods, but if a consumer’s shrink config strips runtime annotation attributes, @JavascriptInterface can be removed and AgentWeb’s checkObject() / WebView reflection will still fail at runtime. Consider also keeping runtime-visible annotation attributes (e.g., RuntimeVisibleAnnotations) so the @JavascriptInterface metadata survives R8/Proguard in consumer apps.
Ship
consumer-rules.proso JS bridge methods survive R8Closes #1072
What changed
agentweb-core/build.gradleand a newagentweb-core/consumer-rules.pro.AgentWeb keeps its own classes via the existing
proguard-rules.pro, but consumer apps that turn on R8 in release builds were not getting any keep rule for@JavascriptInterfacemethods on their own bridge classes. The result was the exact crash the reporter saw:debug builds ran fine because R8 was disabled there. Release APKs failed because the bridge methods had been removed.
The fix ships consumer rules with the AAR so every app that depends on AgentWeb gets the right keep rule automatically. The new file also re-keeps
com.just.agentweb.**to defend against R8 trimming AgentWeb itself when the consumer app uses aggressive shrink configurations.Key snippet
agentweb-core/build.gradledefaultConfig { ... consumerProguardFiles 'consumer-rules.pro' }agentweb-core/consumer-rules.proHow consumers verify
Build a release APK with
minifyEnabled true, run the app, and call any@JavascriptInterfacemethod from the loaded page. The call now resolves instead of throwingJsInterfaceObjectException.