Skip to content

Ship consumer-rules.pro so JS bridge methods survive R8 (closes #1072)#1088

Open
jim-daf wants to merge 2 commits intoJustson:androidxfrom
jim-daf:fix/consumer-rules-jsinterface-issue-1072
Open

Ship consumer-rules.pro so JS bridge methods survive R8 (closes #1072)#1088
jim-daf wants to merge 2 commits intoJustson:androidxfrom
jim-daf:fix/consumer-rules-jsinterface-issue-1072

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 23, 2026

Ship consumer-rules.pro so JS bridge methods survive R8

Closes #1072

What changed

agentweb-core/build.gradle and a new agentweb-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 @JavascriptInterface methods on their own bridge classes. The result was the exact crash the reporter saw:

com.just.agentweb.JsInterfaceObjectException: this object has not offer method
javascript to call, please check addJavascriptInterface annotation was be added

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.gradle

defaultConfig {
    ...
    consumerProguardFiles 'consumer-rules.pro'
}

agentweb-core/consumer-rules.pro

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keep class com.just.agentweb.** { *; }
-dontwarn com.just.agentweb.**

How consumers verify

Build a release APK with minifyEnabled true, run the app, and call any @JavascriptInterface method from the loaded page. The call now resolves instead of throwing JsInterfaceObjectException.

@jim-daf jim-daf marked this pull request as ready for review April 23, 2026 09:48
Copilot AI review requested due to automatic review settings April 23, 2026 09:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 the agentweb-core Android library configuration.
  • Introduce agentweb-core/consumer-rules.pro with keep rules for @JavascriptInterface methods 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.

Comment on lines 14 to +18
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'
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +10
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

-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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants