Obfuscated problem with WebView and javascript

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Attached demo runs well in Release mode but does not in Release (obfuscated mode).

It is a webview knob (with WebViewextras) that controls the volume level of the music.

Try running it in both modes. In obfuscated mode the knob still works but does not trigger the changeValue event anymore.

The .zip is too big for this forum, download it at: http://www.things.io/downloads/knob.zip
 

warwound

Expert
Licensed User
Longtime User
Yes Erel's right, here's the offending code:

B4X:
B4A.CallSub('changeValue', true,e)

Your B4A Sub changeValue will not exist after obfuscation, adding an underscore anywhere in the Sub name and then updating the line in Sub loadKnob:

B4X:
html = html & "B4A.CallSub('changeValue', true,e)"

Should fix things.

The project didn't compile unfortunately - screengrab about missing resource attached.

Was that in the download but not marked read-only perhaps?

Martin.
 

Attachments

  • knob_fail_to_compile.jpg
    knob_fail_to_compile.jpg
    18.6 KB · Views: 252
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Resource

Actually this is the holo style supported by Google, it isn't a separate resource.

When I zip and open the project and compile it works without a problem.

You can use (see Android design guidelines) different holo themes for different API versions.

I will delete it for now because obviously it needs more testing.

Cheers,
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
My B4A installation is set up to compile using the Android API version 8 android.jar - would that explain it?

Martin.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Holo

Could be I always compile with the highest API, Erel seems to advice that. When compiling on the high API I also always do a test run on my oldest device, the HTC Hero.

Cheers,
 
Upvote 0

mixer69

New Member
Licensed User
Longtime User
Hello,

I've got the same problem here.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)

   Dim JSContent As WebViewExtras
   Dim MsgContent As WebView
   Dim HTMLContent As StringBuilder
   Dim HTMLContent2String As String
   
   MsgContent.Initialize("")
   HTMLContent.Initialize
   
   MsgContent.JavaScriptEnabled = True
   JSContent.addWebChromeClient(MsgContent, "")
   JSContent.addJavascriptInterface(MsgContent, "B4A")

   HTMLContent.Append("<script language='JavaScript'>")
   HTMLContent.Append("function sendProfilId(userid){")
   HTMLContent.Append("alert(userid);")
   HTMLContent.Append("B4A.CallSub('GetProfil', true, userid);")
   HTMLContent.Append("}</script>")
   HTMLContent.Append("<img onclick='javascript:sendProfilId(154);' src='http://www.fruityclub.net/site/images/smoove/logo.png' width='100px' />")

   HTMLContent2String = HTMLContent.ToString
   MsgContent.LoadHtml(HTMLContent2String)
   Activity.AddView(MsgContent, 0, 0, 100%x, 100%y)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub GetProfil(UserId As Int)
   Msgbox("ProfilID = " & UserId, "TEST")
End Sub

With or without underscore in the sub name, i've got "java.lang.Exception: Sub getprofil signature does not match expected signature." in debug and release mode. In obfuscated it do nothing !

EDIT: in obfuscated mode, without underscore, it do nothing. With underscore, i've got error message above.

Can you please help ?

Thanks,
remi
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Try the code below. See changes in Callsub and sub name.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)

   Dim JSContent As WebViewExtras
   Dim MsgContent As WebView
   Dim HTMLContent As StringBuilder
   Dim HTMLContent2String As String
   
   MsgContent.Initialize("")
   HTMLContent.Initialize
   
   MsgContent.JavaScriptEnabled = True
   JSContent.addWebChromeClient(MsgContent, "")
   JSContent.addJavascriptInterface(MsgContent, "B4A")

   HTMLContent.Append("<script language='JavaScript'>")
   HTMLContent.Append("function sendProfilId(userid){")
   HTMLContent.Append("alert(userid);")
   HTMLContent.Append("B4A.CallSub('GetProfil_', true, userid);")
   HTMLContent.Append("}</script>")
   HTMLContent.Append("<img onclick='javascript:sendProfilId(154);' src='http://www.fruityclub.net/site/images/smoove/logo.png' width='100px' />")

   HTMLContent2String = HTMLContent.ToString
   MsgContent.LoadHtml(HTMLContent2String)
   Activity.AddView(MsgContent, 0, 0, 100%x, 100%y)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub GetProfil_(UserId As Int)
   Msgbox("ProfilID = " & UserId, "TEST")
End Sub
 
Upvote 0

mixer69

New Member
Licensed User
Longtime User
Thanks for the reply!

Unfortunately, i still get the message 'java.lang.Exception: Sub getprofil_ signature does not match expected signature.' after js alert ...

EDIT:
If i change this line :
B4X:
Sub GetProfil_(UserId As String)

it works! But "UserId" is an integer !
 
Last edited:
Upvote 0
Top