2

I have a Webview with some Javascript interface

public class WebAppInterface {
    @JavascriptInterface
    void buttonClick() {
        listener.onButtonClicked();
    }
}

This is how it's added to the view

webView.addJavascriptInterface(new WebAppInterface(), "Android");

In debug build the listener is working.

In release build, made by Jenkins, it doesn't work.

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "terminal_${variant.versionName}.apk"
                }
            }
        }
    }

It shouldn't be related to Proguard, because minify is disabled.

I tried different Proguard settings anyway, it didn't helped.

How to make it work in release build?

Andrey Rankov
  • 1,964
  • 2
  • 17
  • 33
  • Hi, did you figure out a solve for this? I'm having the exact same issue, these functions are being removed from my release builds. – Vishnu Dec 28 '22 at 12:37

1 Answers1

0

Making the interface method public resolved the issue

public void buttonClick() {
        listener.onButtonClicked();
    }

If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript (the method must also be public). https://developer.android.com/guide/webapps/webview#BindingJavaScript

Andrey Rankov
  • 1,964
  • 2
  • 17
  • 33