Android Question AddJavascriptInterface is invalid when app is release to obfuscated(resolved)

shugeyi

Member
Licensed User
Longtime User
i use AddJavascriptInterface in my app, the code is
B4X:
WebView1.Initialize("WebView1")
WebViewExtras1.Initialize(WebView1)
 
Dim JavascriptInterface1 As DefaultJavascriptInterface
JavascriptInterface1.Initialize
WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
   
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
WebView1.LoadUrl("https://www.b4x.com/android/forum/forums/questions.26/")
 
Sub WebView1_PageFinished (Url As String)
  WebViewExtras1.executeJavascript("B4A.CallSub('JavascriptCallback', true, document.title)") 
End Sub

Sub JavascriptCallback(title As String)
   Log("web page title =  " & title)
End Sub

when i build my app release(obfuscated), i can't get the title
i know the problem is the sub name has been changed because obfuscated
but i don't want to build my app without obfuscate
Are there any other solutions?
thanks
 

Misterbates

Active Member
Licensed User
i use AddJavascriptInterface in my app, the code is
B4X:
WebView1.Initialize("WebView1")
WebViewExtras1.Initialize(WebView1)

Dim JavascriptInterface1 As DefaultJavascriptInterface
JavascriptInterface1.Initialize
WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
  
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
WebView1.LoadUrl("https://www.b4x.com/android/forum/forums/questions.26/")

Sub WebView1_PageFinished (Url As String)
  WebViewExtras1.executeJavascript("B4A.CallSub('JavascriptCallback', true, document.title)")
End Sub

Sub JavascriptCallback(title As String)
   Log("web page title =  " & title)
End Sub

when i build my app release(obfuscated), i can't get the title
i know the problem is the sub name has been changed because obfuscated
but i don't want to build my app without obfuscate
Are there any other solutions?
thanks

Is it possible to include "_" in the callback sub name, e.g. Javascript_Callback? I believe doing that will prevent it being obfuscated.
 
Upvote 0
Top