My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 12987: Javascript to Java Bridge Throws Exception
747 people starred this issue.
Comments by non-members will not trigger notification emails to users who starred this issue.
Back to list
Status:  Unassigned
Owner:  ----

Restricted
  • Only users with Commit permission may comment.


Sign in to add a comment
 
Reported by tony.cas...@gmail.com, Dec 6, 2010
The javascript to java bridge on 2.3 Gingerbread is causing crashes.  This is 100% reproducible using the WebViewDemo application from here: https://code.google.com/p/apps-for-android/source/browse/#svn/trunk/Samples/WebViewDemo.
Note: The project file for that app is a little messed up, however, if you recreate the project, keeping the code the same, you can reproduce the error.  The sample is old, but the code should still run as none of these interfaces have been deprecated.

It is also easily reproducible by creating a simple application that creates a webview, enables javascript, adds a JS interface, then loads a script into the webview. The code for this even simpler app is attached as well as WebViewTest and a secondary Test class as the "bridge".

The demos work as expected when using 2.2

This is a serious issue as it will cause crashes for any app using the webview to do any serious work.  Thanks in advance for taking a look at this.

Attached is the output from logcat as well as the output from adb bugreport.  
log.txt
8.3 KB   View   Download
bug.txt
1.1 MB   View   Download
WebViewTest.java
764 bytes   View   Download
Test.java
149 bytes   View   Download
Dec 6, 2010
#1 taigc...@gmail.com
This bug is critical! Please fix it ASAP!
Dec 7, 2010
#2 Adam.Sch...@gmail.com
Broke for me too
Dec 7, 2010
#3 dave...@gmail.com
This should be set to High Priority. As other comments allude, this is critical and is causing our app (and I am sure others) to crash and potential workarounds are pretty ugly.
Dec 7, 2010
#4 fcin...@gmail.com
It's a silly JNI mistake, please fix it before 2.3 goes alive on devices
Dec 7, 2010
#5 jasons...@gmail.com
Everyone, tell everyone you know to star this issue!  This is a crucial, crucial bug to fix.
Dec 7, 2010
#6 ehern...@gmail.com
Please fix asap!
Dec 7, 2010
#7 yakkyj...@gmail.com
36 people starred this issue and may be notified of changes.  How do I star it?! I agree, this is a pretty big issue, although if you target for 2.2 or below you should be ok. 
Dec 7, 2010
#8 tony.cas...@gmail.com
Hey yakkyjunk, targeting 2.2 does not resolve the issue.  Anything that uses that functionality and is running on 2.3 will encounter this and crash.

(Click on the star next to the word 'Issue' in the blue title bar)
Dec 8, 2010
#9 simon.ma...@gmail.com
This is a critical issue for us as well.
Dec 8, 2010
#10 CommonsG...@gmail.com
I can verify the crash using these other sample projects:

https://github.com/commonsguy/cw-advandroid/tree/master/WebView/GeoWeb1
https://github.com/commonsguy/cw-advandroid/tree/master/WebView/GeoWeb2
https://github.com/commonsguy/cw-abj/tree/master/PhoneGap/Checklist

Note that the latter is a PhoneGap project, suggesting that all PhoneGap-powered apps will fail on Android 2.3 as well.

All of these projects work fine on Android 2.2.

--
Mark Murphy (a Commons Guy)
mmurphy@commonsware.com

Dec 8, 2010
#11 CommonsG...@gmail.com
Actually, those samples I just posted are not good ones, as there may be a separate SIGSEGV related to mock GPS data sent via DDMS. Here is a really tiny sample project that does demonstrate the addJavascriptInterface() problem:

http://commonsware.com/misc/SIGSEGVOne.zip

--
Mark Murphy (a Commons Guy)
mmurphy@commonsware.com

Dec 8, 2010
#12 skyntc...@gmail.com
I was just about to post very similar to Mark's example. My results are exactly the same - crash 100% of the time.
Dec 8, 2010
#14 chunkerc...@gmail.com
The above link is only a partial workaround.

Major issues:

This does not allow for a synchronous response from java. Any javascript code can be rewritten with return callbacks from java in a continuation passing style, but this generally requires a complete restructuring of the affected code base.

The javascript to java interface presented here does not persist across page loads. The original (broken) mechanism is available to any javascript executing within the webview, whether in the parent document or in any nested iframe, and is unaffected by content reloading.
Dec 8, 2010
#15 jasons...@gmail.com
Agreed on both points. That's why this is a workaround, and only for simple cases; the real solution is for the Android team to actually fix the root cause.
Dec 8, 2010
#16 tony.cas...@gmail.com
If you're really looking for a workaround, I think it'd be easier to override the WebChromeClient's onJSAlert method and write a simple parser.  You still can't return values, but you don't have to reload the page.

That said, this does not work for me at all.  I'd have to rewrite almost all of my code to get this working, which is pretty terrible.
Dec 8, 2010
#17 fcin...@gmail.com
A good news for you guys, the crash doesn't happen on real Nexus S device, so basically this is another bug on emulator as NIO on 2.2
Dec 8, 2010
Project Member #18 romannu...@google.com
Repro'd on the 2.3 emulator; verified that this is NOT reproducible on a Nexus S.
Status: Reviewed
Labels: Component-Browser Version-2.3
Dec 9, 2010
#19 tony.cas...@gmail.com
Great, that's good news.  Any idea when we might get a new emulator build?  Also, is there any way to get early device builds for the Nexus One?  Alternatively, is there a program we can apply to for early access in the future?
Dec 12, 2010
#20 Siriquelle
Please solve his.
Dec 15, 2010
#21 abba...@gmail.com
I encountered this issue too.  I upgraded the SDK to include version 2.3 of the emulator and our app crashed, so I decided to check the WebViewDemo app to make sure it wasn't a problem with our app.  The demo app crashed right away, and that led me to this page.  Hopefully they can fix it soon, because this JavaScript functionality is a major part of our app.
Dec 16, 2010
#22 andy.tri...@gmail.com
learn to qa
Dec 16, 2010
#23 hnbc8...@gmail.com
please solve as soon as, my app depend on the javascript.
Dec 17, 2010
#25 aleksand...@gmail.com
Grrr, client project testing is not possible on 2.3 emulator because of this issue and 2.2 has issue with camera. Disappointed with emulator.
Dec 19, 2010
#26 ate...@gmail.com
This is a critical issue for us as well, please fix this ASAP.

Thanks.
Dec 19, 2010
#27 usa2...@gmail.com
This is a big issue, please fix this quickly.

Thanks
Dec 20, 2010
#28 jellomas...@gmail.com
I'm also experiencing this issue in the 2.3 emulator... when including js in the webview demo... the 
Dec 20, 2010
#29 HonsoHanWriting
Just want to confirm that are you guys getting the following like I do?

12-20 19:29:34.582: WARN/dalvikvm(725): JNI WARNING: jarray 0x4074f6e0 points to non-array object (Ljava/lang/String;)
12-20 19:29:34.622: INFO/dalvikvm(725): "WebViewCoreThread" prio=5 tid=9 NATIVE
12-20 19:29:34.622: INFO/dalvikvm(725):   | group="main" sCount=0 dsCount=0 obj=0x40521328 self=0x26bea8
12-20 19:29:34.622: INFO/dalvikvm(725):   | sysTid=734 nice=0 sched=0/0 cgrp=default handle=2539488
12-20 19:29:34.632: INFO/dalvikvm(725):   | schedstat=( 5341953614 5808331660 581 )
12-20 19:29:34.632: INFO/dalvikvm(725):   at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-20 19:29:34.632: INFO/dalvikvm(725):   at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-20 19:29:34.642: INFO/dalvikvm(725):   at android.webkit.WebViewCore.access$3300(WebViewCore.java:53)
12-20 19:29:34.652: INFO/dalvikvm(725):   at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1158)
12-20 19:29:34.652: INFO/dalvikvm(725):   at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 19:29:34.652: INFO/dalvikvm(725):   at android.os.Looper.loop(Looper.java:123)
12-20 19:29:34.652: INFO/dalvikvm(725):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
12-20 19:29:34.662: INFO/dalvikvm(725):   at java.lang.Thread.run(Thread.java:1019)
12-20 19:29:34.672: ERROR/dalvikvm(725): VM aborting
12-20 19:29:34.852: INFO/DEBUG(30): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-20 19:29:34.852: INFO/DEBUG(30): Build fingerprint: 'generic/sdk/generic:2.3/GRH55/79397:eng/test-keys'
12-20 19:29:34.862: INFO/DEBUG(30): pid: 725, tid: 734  >>> XXXXXXXX <<<
12-20 19:29:34.862: INFO/DEBUG(30): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d
12-20 19:29:34.872: INFO/DEBUG(30):  r0 fffffebc  r1 deadd00d  r2 00000026  r3 00000000
12-20 19:29:34.872: INFO/DEBUG(30):  r4 81da45c8  r5 4074f6e0  r6 81d8592c  r7 0026d2b8
12-20 19:29:34.872: INFO/DEBUG(30):  r8 44174b54  r9 43d72e4c  10 43d72e34  fp 41edd82c
12-20 19:29:34.891: INFO/DEBUG(30):  ip 81da4728  sp 44174348  lr afd19375  pc 81d45a02  cpsr 20000030
12-20 19:29:35.912: INFO/DEBUG(30):          #00  pc 00045a02  /system/lib/libdvm.so
12-20 19:29:35.912: INFO/DEBUG(30):          #01  pc 000376fc  /system/lib/libdvm.so
12-20 19:29:35.912: INFO/DEBUG(30):          #02  pc 000399c4  /system/lib/libdvm.so
12-20 19:29:35.922: INFO/DEBUG(30):          #03  pc 0003a4a0  /system/lib/libdvm.so
12-20 19:29:35.932: INFO/DEBUG(30):          #04  pc 0032b6d6  /system/lib/libwebcore.so
12-20 19:29:35.952: INFO/DEBUG(30):          #05  pc 002a4da4  /system/lib/libwebcore.so
12-20 19:29:35.952: INFO/DEBUG(30):          #06  pc 001a6136  /system/lib/libwebcore.so
12-20 19:29:35.952: INFO/DEBUG(30):          #07  pc 002a5870  /system/lib/libwebcore.so
12-20 19:29:35.962: INFO/DEBUG(30):          #08  pc 00359e36  /system/lib/libwebcore.so
12-20 19:29:35.972: INFO/DEBUG(30):          #09  pc 0035d18e  /system/lib/libwebcore.so
12-20 19:29:35.972: INFO/DEBUG(30):          #10  pc 0036b078  /system/lib/libwebcore.so
12-20 19:29:35.982: INFO/DEBUG(30):          #11  pc 003627ac  /system/lib/libwebcore.so
12-20 19:29:35.982: INFO/DEBUG(30):          #12  pc 0029fb24  /system/lib/libwebcore.so
12-20 19:29:36.002: INFO/DEBUG(30):          #13  pc 0023367e  /system/lib/libwebcore.so
12-20 19:29:36.002: INFO/DEBUG(30):          #14  pc 00239c0c  /system/lib/libwebcore.so
12-20 19:29:36.011: INFO/DEBUG(30):          #15  pc 00237a28  /system/lib/libwebcore.so
12-20 19:29:36.011: INFO/DEBUG(30):          #16  pc 00237b32  /system/lib/libwebcore.so
12-20 19:29:36.022: INFO/DEBUG(30):          #17  pc 0023adba  /system/lib/libwebcore.so
12-20 19:29:36.022: INFO/DEBUG(30):          #18  pc 0023af4e  /system/lib/libwebcore.so
12-20 19:29:36.042: INFO/DEBUG(30):          #19  pc 000f80c0  /system/lib/libwebcore.so
12-20 19:29:36.042: INFO/DEBUG(30):          #20  pc 000f8c66  /system/lib/libwebcore.so
12-20 19:29:36.052: INFO/DEBUG(30):          #21  pc 001b81fa  /system/lib/libwebcore.so
12-20 19:29:36.062: INFO/DEBUG(30):          #22  pc 001b82f2  /system/lib/libwebcore.so
12-20 19:29:36.062: INFO/DEBUG(30):          #23  pc 001b8318  /system/lib/libwebcore.so
12-20 19:29:36.072: INFO/DEBUG(30):          #24  pc 00017d34  /system/lib/libdvm.so
12-20 19:29:36.082: INFO/DEBUG(30): code around pc:
12-20 19:29:36.082: INFO/DEBUG(30): 81d459e0 447a4479 ed0cf7d1 20004c09 ee34f7d1 
12-20 19:29:36.092: INFO/DEBUG(30): 81d459f0 447c4808 6bdb5823 d0002b00 49064798 
12-20 19:29:36.092: INFO/DEBUG(30): 81d45a00 700a2226 eea0f7d1 0004355f 0004511d 
12-20 19:29:36.102: INFO/DEBUG(30): 81d45a10 0005ebd2 fffffebc deadd00d b510b40e 
12-20 19:29:36.102: INFO/DEBUG(30): 81d45a20 4c0a4b09 447bb083 aa05591b 6b5bca02 
12-20 19:29:36.112: INFO/DEBUG(30): code around lr:
12-20 19:29:36.112: INFO/DEBUG(30): afd19354 b0834a0d 589c447b 26009001 686768a5 
12-20 19:29:36.112: INFO/DEBUG(30): afd19364 220ce008 2b005eab 1c28d003 47889901 
12-20 19:29:36.122: INFO/DEBUG(30): afd19374 35544306 d5f43f01 2c006824 b003d1ee 
12-20 19:29:36.122: INFO/DEBUG(30): afd19384 bdf01c30 000281a8 ffffff88 1c0fb5f0 
12-20 19:29:36.132: INFO/DEBUG(30): afd19394 43551c3d a904b087 1c16ac01 604d9004 
12-20 19:29:36.132: INFO/DEBUG(30): stack:
12-20 19:29:36.132: INFO/DEBUG(30):     44174308  00000015  
12-20 19:29:36.132: INFO/DEBUG(30):     4417430c  afd18407  /system/lib/libc.so
12-20 19:29:36.142: INFO/DEBUG(30):     44174310  afd4270c  /system/lib/libc.so
12-20 19:29:36.142: INFO/DEBUG(30):     44174314  afd426b8  /system/lib/libc.so
12-20 19:29:36.152: INFO/DEBUG(30):     44174318  00000000  
12-20 19:29:36.152: INFO/DEBUG(30):     4417431c  afd19375  /system/lib/libc.so
12-20 19:29:36.162: INFO/DEBUG(30):     44174320  0026bea8  [heap]
12-20 19:29:36.162: INFO/DEBUG(30):     44174324  afd183d9  /system/lib/libc.so
12-20 19:29:36.162: INFO/DEBUG(30):     44174328  0026d2b8  [heap]
12-20 19:29:36.172: INFO/DEBUG(30):     4417432c  0005ebd2  [heap]
12-20 19:29:36.172: INFO/DEBUG(30):     44174330  4074f6e0  /dev/ashmem/dalvik-heap (deleted)
12-20 19:29:36.172: INFO/DEBUG(30):     44174334  81d8592c  /system/lib/libdvm.so
12-20 19:29:36.182: INFO/DEBUG(30):     44174338  0026d2b8  [heap]
12-20 19:29:36.182: INFO/DEBUG(30):     4417433c  afd18437  /system/lib/libc.so
12-20 19:29:36.191: INFO/DEBUG(30):     44174340  df002777  
12-20 19:29:36.191: INFO/DEBUG(30):     44174344  e3a070ad  
12-20 19:29:36.191: INFO/DEBUG(30): #00 44174348  00000001  
12-20 19:29:36.191: INFO/DEBUG(30):     4417434c  81d37701  /system/lib/libdvm.so
12-20 19:29:36.191: INFO/DEBUG(30): #01 44174350  00000001  
12-20 19:29:36.191: INFO/DEBUG(30):     44174354  81d399c9  /system/lib/libdvm.so

Dec 27, 2010
#30 Landry....@gmail.com
This is a very bad! Please fix it ASAP
Dec 28, 2010
#31 LeifRi...@gmail.com
I also have problems with this. (I think at least)

My app crashes when run on the 2.3 emulator with the log printed above.
I don't use any webview myself in the app startup, but I guess some of the ad network SDKs might do, thus causing the crash (?).
If so, this will possibly break most apps with ads in them... 

Why is this bug still rated only priority medium? To me it is a blocker.

Maybe it's only in the emulator? If so, could we please get an official confirmation on that? But even so, I won't be able to test the app on the 2.3 platform before publishing.

Dec 29, 2010
#32 HonsoHanWriting
Agree, this is a very serious bug. Please raise the priority.
Dec 30, 2010
#33 jznomo...@gmail.com
I get this error on my builds custom builds for my msm7227 cell phone device when running gmail.
Jan 5, 2011
#34 Josiah.H...@gmail.com
Very serious bug, fix please! Raise the priority.
Jan 6, 2011
#35 poowa...@gmail.com
Please fix this ASAP. Thank you.

Jan 6, 2011
#36 sammorri...@gmail.com
Experiencing the same problem here.  Please fix.
Jan 7, 2011
#37 CKu...@gmail.com
I have the same issue when interfacing on 2.3. please someone from google give some feedback.
Jan 10, 2011
#38 vinaym...@gmail.com
Whole development is stuck!
Please fix asap
Jan 10, 2011
#39 sammorri...@gmail.com
It shows the status of this has been reviewed, what was the outcome of that review??
Jan 10, 2011
#40 hbls00...@gmail.com
I think this is being treated as quite a low priority since it only appears to be a bug in the emulator and not real devices. Of course a new release of the emulator (e.g. 2.3.0.1) wouldn't go amiss in fixing this.
Jan 10, 2011
#41 fcin...@gmail.com
I think it's high priority even it appears on emulator currently. Please note that most customized OS are built from the public source code of Android which is mostly the same as emulator. I've already seen the bug is transferred to devices with customized 2.3 rom.
Jan 11, 2011
#42 bruno.ab...@gmail.com
Same issue. My app depends on Javascript. Please fix.
Jan 13, 2011
#43 nwucompu...@gmail.com
Pleas fix bug as soon as possible!My app can't run on 2.3
Jan 13, 2011
#44 long...@gmail.com
I have the similar issue and who can tell me the method of analyzing the LogCat log like this issue.
Jan 15, 2011
#45 sakamoto...@gmail.com
Please fix this quickly. 
Jan 19, 2011
#46 winvi...@gmail.com
Please make this issue as critical and resolve it ASAP.
Jan 20, 2011
#47 oliver.scholt@gmx.de
Same Issue , same Log, even with Phonegap Example Apps. Please fix this.
Jan 21, 2011
#48 m...@wias.no
Same problem. This have to be fixed soon.. PLEASE...
Jan 22, 2011
#49 iuga_ma...@yahoo.com
Voted to be fixed as well. I think they'll do it next release but not until then.
Jan 24, 2011
#50 d...@ctrl-bit.com
Please fix, I use webview/JS alot....Ouch.
Jan 26, 2011
#51 fcin...@gmail.com
the new released 2.3.1 doesn't fix it...
Jan 26, 2011
#52 abba...@gmail.com
I was so hopeful when I saw that there was a new release 2.3.1.  I downloaded it and the same problem is still there.
Jan 27, 2011
#53 nic...@webehome.com
I have the same problem both in the 2.3 emulator and on ZTE Blade phone using 2.2. It works perfect on for example HTC Desire and some other Android phones we have tested. So it is actually relating both to real devices and to other released than 2.3. We can't make an official release of our application until this is corrected.
Jan 31, 2011
#54 mathonph...@gmail.com
Amazon Marketplace says my Phonegap app can not run in their tests due to this error. They also say it fails on the Droid Incredible running Android OS 2.2
Jan 31, 2011
#55 ian.ha...@gmail.com
This is a critical bug and should be fixed innan out-of-band update, and nothing less.
Feb 3, 2011
#56 csaff...@gmail.com
Please fix this bug, this is critical, many apps based on webview are not working on Android 2.3.1
Feb 3, 2011
#57 stach...@gmail.com
this is ctritical! 
Feb 3, 2011
#58 jameseis...@gmail.com
Fix please!
Feb 5, 2011
#59 you.m...@gmail.com
is there a workaround for this?
Feb 5, 2011
#60 bkurz...@gmail.com
The only workaround that I know of is to test on the 2.2 or on the device. In my app, there is no 2.3 dependent functionality so it works fine, but I am trying to get my hands on a real device anyway because I understand that the emulator is quite slow.
Feb 7, 2011
#61 ko0tae...@gmail.com
it's critical...
Feb 9, 2011
#62 pmue...@gmail.com
just tried the brand-spanking-new 2.3.3 emulator image.  Same problem :-(
Feb 12, 2011
#63 jpsa...@gmail.com
This is critical for me too. Testing all platforms for android apps is critical. Even if it only happnes on simulator, which is not yet confirmed, it's critical.
Feb 14, 2011
#64 sakamoto...@gmail.com
I compiled gingerbread for HTC Magic and it not work.
Is this not only emulator bug?
Feb 18, 2011
#65 xavier.k...@gmail.com
It should be fixed asap
Feb 20, 2011
#66 fred.gr...@gmail.com
Okay folks, other phonegap developer are finding the same bug on real devices,, its effing real serious problem now.

We need to start tracking this by android OS version for emulator, android device OS version , webkit version, etc 

If I get the dev job I interview on Monday I am writing an effing parser to fix..
Feb 20, 2011
#67 jokeyrh...@gmail.com
The way I see it, unless it's a super-critical _security_ flaw it will not get fixed in any current version of Android. Google is currently working on Gingerbread 2.4 and Honeycomb, so all we can do is pray that they have corrected this issue in those releases.

I'm not sure what's so drastically wrong with Gingerbread 2.3, but there is still only one device out that has it officially: the Nexus S. Google hasn't updated the Nexus 1 yet for some mysterious reason, and none of the manufacturers have released any official updates to it (no surprise there though).

Just target Froyo with your PhoneGap applications for the time being, and wait for Gingerbread 2.4 which will probably be the widely used version. This reminds me of the 2 Eclairs, although I can't remember what was broken in the first one...
Feb 20, 2011
#68 fred.gr...@gmail.com
Guys, this might be good news..

Try switching addJavascriptInterface to after loadURL

Its not fully tested yet..need to do a better example and fully test it..but Mark Murphy's example with that change is getting no errors.. Yeah!
Feb 20, 2011
#69 fred.gr...@gmail.com
The logcat output when switching addJavascriptInterface to after loadURL:


02-20 21:34:52.452: DEBUG/dalvikvm(486): GC_CONCURRENT freed 103K, 69% free 319K/1024K, external 0K/0K, paused 2ms+1ms
02-20 21:34:52.462: DEBUG/jdwp(486): Got wake-up signal, bailing out of select
02-20 21:34:52.462: DEBUG/dalvikvm(486): Debugger has detached; object registry had 1 entries
02-20 21:34:56.692: INFO/ActivityManager(75): Displayed com.mobilebytes.brokenaddjavascriptinterface/.MainActivity: +4s298ms
02-20 21:35:05.141: DEBUG/dalvikvm(367): GC_EXPLICIT freed 7K, 54% free 2543K/5511K, external 716K/1038K, paused 91ms
02-20 21:35:10.281: DEBUG/dalvikvm(423): GC_EXPLICIT freed 317K, 54% free 2538K/5511K, external 716K/1038K, paused 219ms
02-20 21:35:15.223: DEBUG/dalvikvm(438): GC_EXPLICIT freed 481K, 55% free 2595K/5703K, external 716K/1038K, paused 138ms
02-20 21:35:20.251: DEBUG/dalvikvm(148): GC_EXPLICIT freed 93K, 51% free 2934K/5895K, external 2048K/2461K, paused 158ms
02-20 21:39:33.452: DEBUG/SntpClient(75): request time failed: java.net.SocketException: Address family not supported by protocol
02-20 21:44:33.461: DEBUG/SntpClient(75): request time failed: java.net.SocketException: Address family not supported by protocol
02-20 21:49:33.472: DEBUG/SntpClient(75): request time failed: java.net.SocketException: Address family not supported by protocol


As you can see no errors...

That would mean something not being loaded that addJavascriptInterface needs until loadURL is called..in 2.2, 2.3 emulators and some devices
Feb 21, 2011
#70 pmue...@gmail.com
I'm unable to make addJavascriptInterface to work, even after calling it after loadUrl().  If I call addJavascriptInterface immediately after the loadUrl(), I get the same trap as if I had put it before.  If I make the call well after loadUrl() - I do it in a consoleMessage callback - then the "object" I'm trying to install never gets installed.

Perhaps it's a bug in my code.  Anyone else have any luck?
Feb 21, 2011
#71 cszu...@gmail.com
So far I've only had a chance to try moving addJavascriptInterface() to immediately after loadUrl(), but it didn't help.
Feb 21, 2011
#72 fred.gr...@gmail.com
Sorry folks I still get same locat errors.

However, if I do not touch the app no user input I am not seeing WebViewCore messages such as th AddJavascritInterface succeeded so is this a WebViewCore initialization and native lib interference?
Feb 21, 2011
#73 nyse.n...@gmail.com
Please fix this bug, this is critical.
Feb 22, 2011
#74 jokeyrh...@gmail.com
The Honeycomb emulator was officially released today, and I think I noticed the Gingerbread emulator getting some updates. Anyone tried this in the new SDK yet?
Feb 22, 2011
#75 typo...@gmail.com
Works in 3.0 emulator.

For the 2.3.1 and 2.3.3 emulators - no change.


02-22 22:47:55.529: WARN/dalvikvm(404): JNI WARNING: jarray 0x4051a6e8 points to non-array object (Ljava/lang/String;)
02-22 22:47:55.538: INFO/dalvikvm(404): "WebViewCoreThread" prio=5 tid=9 NATIVE
02-22 22:47:55.538: INFO/dalvikvm(404):   | group="main" sCount=0 dsCount=0 obj=0x40520330 self=0x1f5278
02-22 22:47:55.538: INFO/dalvikvm(404):   | sysTid=412 nice=0 sched=0/0 cgrp=default handle=2054032
02-22 22:47:55.548: INFO/dalvikvm(404):   | schedstat=( 1467256456 1411922893 266 )
02-22 22:47:55.548: INFO/dalvikvm(404):   at android.webkit.LoadListener.nativeFinished(Native Method)
02-22 22:47:55.558: INFO/dalvikvm(404):   at android.webkit.LoadListener.nativeFinished(Native Method)
02-22 22:47:55.570: INFO/dalvikvm(404):   at android.webkit.LoadListener.tearDown(LoadListener.java:1200)
02-22 22:47:55.570: INFO/dalvikvm(404):   at android.webkit.LoadListener.handleEndData(LoadListener.java:721)
02-22 22:47:55.577: INFO/dalvikvm(404):   at android.webkit.LoadListener.handleMessage(LoadListener.java:219)
02-22 22:47:55.577: INFO/dalvikvm(404):   at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 22:47:55.577: INFO/dalvikvm(404):   at android.os.Looper.loop(Looper.java:123)
02-22 22:47:55.577: INFO/dalvikvm(404):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
02-22 22:47:55.587: INFO/dalvikvm(404):   at java.lang.Thread.run(Thread.java:1019)
02-22 22:47:55.587: ERROR/dalvikvm(404): VM aborting
02-22 22:47:55.798: INFO/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-22 22:47:55.798: INFO/DEBUG(31): Build fingerprint: 'generic/sdk/generic:2.3.1/GSI11/93351:eng/test-keys'
02-22 22:47:55.798: INFO/DEBUG(31): pid: 404, tid: 412  >>> -------------------------------------- <<<
02-22 22:47:55.808: INFO/DEBUG(31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d

02-22 22:53:51.301: WARN/dalvikvm(418): JNI WARNING: jarray 0x40518c48 points to non-array object (Ljava/lang/String;)
02-22 22:53:51.310: INFO/dalvikvm(418): "WebViewCoreThread" prio=5 tid=9 NATIVE
02-22 22:53:51.310: INFO/dalvikvm(418):   | group="main" sCount=0 dsCount=0 obj=0x40520988 self=0x1f4ec8
02-22 22:53:51.310: INFO/dalvikvm(418):   | sysTid=426 nice=0 sched=0/0 cgrp=default handle=2054608
02-22 22:53:51.310: INFO/dalvikvm(418):   | schedstat=( 1769120282 2152704812 298 )
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.LoadListener.nativeFinished(Native Method)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.LoadListener.nativeFinished(Native Method)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.LoadListener.tearDown(LoadListener.java:1200)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.LoadListener.handleEndData(LoadListener.java:721)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.LoadListener.handleMessage(LoadListener.java:219)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.os.Looper.loop(Looper.java:123)
02-22 22:53:51.310: INFO/dalvikvm(418):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
02-22 22:53:51.310: INFO/dalvikvm(418):   at java.lang.Thread.run(Thread.java:1019)
02-22 22:53:51.310: ERROR/dalvikvm(418): VM aborting
02-22 22:53:51.322: DEBUG/dalvikvm(277): GC_EXPLICIT freed 86K, 54% free 2718K/5831K, external 716K/1038K, paused 7092ms
02-22 22:53:51.431: INFO/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-22 22:53:51.431: INFO/DEBUG(31): Build fingerprint: 'generic/sdk/generic:2.3.3/GRI34/101070:eng/test-keys'
02-22 22:53:51.431: INFO/DEBUG(31): pid: 418, tid: 426  >>> -------------------------------------- <<<
02-22 22:53:51.431: INFO/DEBUG(31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d

Feb 23, 2011
#76 pmue...@gmail.com
Works for me in the 3.0 emulator as well.  It appears that the 3.0 emulator still uses JSC (try eval("\") and look at the exception).
Mar 7, 2011
#78 ian.ha...@gmail.com
Frankly, the lack of response (or acknowledgment) by Google regarding this issue is a cataclysmic failure and a black eye for the Android platform. By not addressing this, Google is making it clear that they do not care about their developers nor do they care about the operating system. Pathetic. This makes Apple seem open.
Mar 7, 2011
#79 zzr12...@gmail.com
This is ctritical...
Mar 7, 2011
#80 jpsa...@gmail.com
Ahah yes, I'm also amazed by the lack of response by google on this one. 
Mar 7, 2011
#81 ben.th...@gmail.com
I'd put good money on the lack of response being that it's fixed in Honeycomb, and the fix will be back-ported into 2.4 (which is still Gingerbread), and they'll never bother to fix 2.3 because 2.3 won't actually end up on devices other than the Nexus S. 

Of course, they should've come out and actually said that officially.....
Mar 7, 2011
#82 cszu...@gmail.com
I just realized that no one announced this in this thread: the issue appears to be fixed in the version of Gingerbread that got pushed to the Nexus One last week (2.3.3).

The lack of official response is still a bummer, but it looks like disaster has been averted.
Mar 7, 2011
#83 jasons...@gmail.com
The issue has never shown itself on the phone.  It has always been on the emulator.
Mar 10, 2011
#84 ashwin.r...@gmail.com
This is problem with 2.3 emulator and Google Apis version 9
Mar 12, 2011
#85 ajmeraax...@gmail.com
Yes its a confirmed bug in android 2.3.3 level 9..I tested it on  i get the same log mentioned above....
Mar 17, 2011
#87 CommonsG...@gmail.com
The Nexus S never has suffered from this problem and does not now (2.3.3). Please try the sample apps from comment #10.
Mar 19, 2011
#88 droidwol...@gmail.com
the same problem on nexus one 2.3.3!
Mar 21, 2011
#89 liaoled...@gmail.com
the same problem.
Mar 22, 2011
#90 emilnet....@gmail.com
Same problem Galaxy S I9000XWJV1 
Mar 23, 2011
#91 linu...@gmail.com
the same problem on emutor
Mar 23, 2011
#92 goalst...@gmail.com
Apparently, a PhoneGap developer named Bryce Curtis has addressed this issue as it affects PhoneGap by implementing a creative workaround that eliminates PhoneGap's dependency upon addJavascriptInterface(). From what I can tell, his fix is likely to go into the next (0.9.5) release of PhoneGap.

In particular, this fix would seem to restore PhoneGap's plugin functionality. It may fix some or all of the PhoneGap problems reported above that were due to its dependency upon addJavascriptInterface().

Since PhoneGap plugins provide an alternative (for PhoneGap apps) to using addJavascriptInterface() for crossing the Javascript to Java boundary, once Bryce's fix eliminating PhoneGap's own dependency upon addJavascriptInterface goes in, it seems possible that applications using PhoneGap that are presently dependent upon addJavascriptInterface() might be able to resolve the problems caused by the addJavascriptInterface() anomalies reported here by recoding their Javascript-to-Java bridge code to use PhoneGap plugins instead of using addJavascriptInterface(). And it seems possible that apps already using the plugin facility will start to work better in Android 2.3 once they update to a PhoneGap version that includes this fix.

It also seems possible that non-PhoneGap Android apps that need to communicate between a WebView and Java might be able to adapt Bryce's approach to their own needs, although since it was designed primarily as a workaround to restore PhoneGap's own functionality it will not necessarily be as pretty an approach as using the plugin facility itself.

Note that I'm reporting this second hand, as something I came across while searching for an alternative to addJavascriptInterface() for my own development. I'm relatively new to PhoneGap, and can't claim to fully understand Bryce's code myself. However, the code itself can be found here:

https://github.com/phonegap/phonegap-android/commit/2bc7bd6768be3d82eab2e1b4f295abebffa79359

and a discussion of the problem that includes Bryce can be found here:

http://phonegap.lighthouseapp.com/projects/20118/tickets/99-phonegap-apps-rejected-by-amazon-marketplace#ticket-99-12

Once again, I can't be sure that I have accurately reported the above, so if I've misread this discussion and development, somebody please post a correction. But since no one else had mentioned this so far on this issue list, and since it appears to me, given what I do understand of it, to be highly pertinent to this issue, I wanted to make it known here. When in doubt, please refer to the two links above and to those actually involved in addressing this very significant issue.
Mar 23, 2011
#93 goalst...@gmail.com
Also, just found the following thread with a recent note from Bryce Curtis at the end regarding his fix:

http://groups.google.com/group/phonegap/browse_thread/thread/a2b6ac44ea798ce4
Apr 11, 2011
#94 wojciech...@gmail.com
the same problem.
Apr 18, 2011
#95 allstars...@gmail.com
this seems to be a bug in the default JS engine(JSC) on emulator
in mydroid emulator build 
if you enable v8 as default JS engine 
this crashes is gone

this is also the reason why this crash will NOT happen on the device(nexus S)
Apr 18, 2011
#96 sjkliter...@gmail.com
Its been a while, it should have been fixed by now. Serious issue for developers.
Apr 18, 2011
#97 sjkliter...@gmail.com
Has someone found a workaround, for developers not using PhoneGap.
Also, enabling v8 engine is a solution that cannot be used for devices. Because it is required to rebuild image. I am beginner, dont mind if this question is awfully noob. Thanks.
Apr 19, 2011
#98 lik...@126.com
the issue exists now.
Apr 28, 2011
#99 outofcof...@gmail.com
As usual, this screws small developers who can't afford to buy every phone on the market to test. Can I test my app on 2.3 now? No, because the emulator is buggy. Note this isn't the first issue - the LVL tools also don't work on 2.3.
Apr 28, 2011
#100 sjkliter...@gmail.com
Agreed! And even for smaller developers like me who cant even figure out how the fix works for webview only. This is a pain in the ass.
May 4, 2011
#101 a3450170...@gmail.com
I'm work on the framework,I've resolved it on our tablet and written it here.
my English is poor, so I hope you can understand.
http://blog.csdn.net/a345017062/archive/2011/05/04/6394864.aspx
May 10, 2011
#102 efferent...@gmail.com
2.2 seems destined to become Google's XP, while 2.3 is Vista. Or maybe 2.3 is Windows Me and 3.0 is Vista. Anyway my point is please fix this.
May 16, 2011
#103 geoff...@gmail.com
is it fixed in 2.3.4? 
May 24, 2011
#105 tringuye...@gmail.com
This problem makes me a big trouble .Has Anyone known how to fix it yet ?


May 26, 2011
#106 dan.maye...@gmail.com
I am not sure if this bug is real on devices or just in the emulator as I hear some rumors, but it still is crashing my code on the 2.3.3 emulator which I thought had received a fix.
May 27, 2011
#107 barkha.d...@gmail.com
Any updates on this issue....any workaround solution which is completely feasible
Jun 6, 2011
#108 barkha.d...@gmail.com
If we make a debug build for libwebcore and then use addJavaScriptInterface api it do not crash, strange, hard to make out what is the issue
Jun 8, 2011
#109 bows...@gmail.com
The issue is when the API returns.  I've been banging my head on this issue for months, but if you look at Comment 101, you can see that the issue is related to issues with the JNI bridge.  However, I don't see any fix to this.  After looking at the CTS, it SHOULD (and probably has) cause the CTS to fail, which may explain why there are very few low-end phones that run Android 2.3, since they would never pass that test.
Jun 20, 2011
#110 rajesh.k...@gmail.com
We have a similar feature which needs to be supported on 2.3.3, but it seems to be failing. When will this be fixed.
Jun 22, 2011
#111 kirualex@gmail.com
 This issue seems clearly to be a crucial one and there was no change since...December 2010?
Are you kidding me?
Jun 28, 2011
#112 Jonathan...@gmail.com
Wait, JS to Java breaks on Gingerbread?? Not having Gingerbread, this is the first I've heard of this, and the app I am developing fundamentally relies on this!
Jul 1, 2011
#113 keating...@gmail.com
Are people only seeing this on devices?  There is some thrash in the comments and it is hard to tell if it is only the emulator or the phones as well.

If you are seeing it on a real phone, can you send us which phone model?   We are trying to reproduce?

Also, how are people handling this crash bug in their apps?  Targeting around it?

Thx everyone for the help!
Jul 5, 2011
#114 sandy....@gmail.com
This is terrible. I am trying to be a responsible developer by testing my code on Gingerbread (I only got a 2.2 device on hand), yet I am punished and wasted my whole morning to trace my code to discover this bug. Even if the bug just occurred on the emulator, it should be fixed asap!
Jul 9, 2011
#115 jinus2...@gmail.com
I am learning [Hello Android] with simulator of version 2.3.3 and get crashed.
I changed the version of simulator to 2.2 after reading comments above and passed the test.
However I want the question be solved ASAP, just like everyone wishes.
Jul 14, 2011
#116 dingyong...@gmail.com
May i know when will this be fixed? in 2.3.5 ?
Do google provide any emergency workaround ?? 
Jul 21, 2011
#117 joe.pemb...@gmail.com
I have done some investigation into this bug, and I believe it is a problem introduced in the JSC javascript engine in Gingerbread.

First, some background:

Versions of Android 2.2 and greater include the v8 javascript engine in addition to the original WebKit Javascript engine (JavaScriptCore, or JSC).  The vast majority of devices use v8, but not necessarily all - some low-memory devices may apparently use JSC.  From the WebKit makefile:

# The default / alternative engine depends on the device class.
# On devices with a lot of memory (e.g. Passion/Sholes), the
# default is V8. On everything else, the only choice is JSC.
# TODO: use ARCH_ARM_HAVE_ARMV7 once that variable is added to
# the build system.

However, emulator images always use JSC.  You can determine which JS engine is in use at runtime through the following javascript snippet:


if (window.devicePixelRatio) { //If WebKit browser
   var st = escape(navigator.javaEnabled.toString());
   if (st === 'function%20javaEnabled%28%29%20%7B%20%5Bnative%20code%5D%20%7D') {
      document.write('V8 detected');
   } else {
      document.write('JSC detected');
   }
} else {
  document.write("Not a WebKit browser");
}


My Nexus one has 2.3.4 on it, and when I ran this piece of javascript it reported 'v8', and I wasn't able to repro this bug.  

I then downloaded and build the android source with the JS_ENGINE environment variable set to 'jsc', then installed the custom image onto my Nexus One.  Now my phone reports having 2.3.4 on it, and the JS snippet above reports 'jsc', and I can consistently repro this JNI warning.  So this bug _can_ happen on devices, and likely is happening in the wild on certain low-memory devices.

Unfortunately, I have not found any workaround other than detecting at runtime which JS engine is in use and conditionally disabling JavaScript-to-Java behavior in our app.
Aug 10, 2011
#118 zhaowei1...@gmail.com
I tried in HTC desire with a custom rom of 2.3, it's not crashed but the javascriptinterface is not called. The same is in the emultor. My app relies on this feature. please fix it asap.
Aug 14, 2011
#119 matteo.g...@gmail.com
The addJavascriptInterface seems to work fine, the error seems to be raised once a method is invoked through the interface.
Leaving off any method invokation and keeping the (this way useless, so should be fixed) addJavascriptInterface seems to avoid the crash.

Anyone else got this same result?

As real device I have a Galaxy S I9000 updated on Gingerbread via official channels, it works fine (I suppose it uses the V8 interpreter).

 
Aug 23, 2011
#120 timt4s...@gmail.com
Just to confirm comment 117. I compiled android 2.3.4 using JS_ENGINE=v8 to get a emulator image using v8 Javascript (defaults to jsc). This problem is not reproducible in the emulator. (though this configuration has other problems: most Javascript dies with ILL_ILLOPC exception, due to v8 requiring a later instruction set than the emulator provides).

I guess older phones should only upgrade to 2.2.
Sep 5, 2011
#121 firedot...@gmail.com
this problem seems  caused by template callJNIMethod<>, replace it with direct function define and replace all call in JNIBridge.cpp JavaClassJSC.cpp JavaInstanceJSC.cpp, it works fine on emulator,but it is strange  why v8 engine doesn't have this problem, it also call callJNIMethod<> func
Sep 6, 2011
#122 jinh...@gmail.com
Very serious bug, fix please! 
Sep 20, 2011
#123 matej.sy...@gmail.com
This is a total NFC showstopper. Is this politically intentional? Please fix this ASAP. 
Sep 20, 2011
#124 matth...@gmail.com
This is frustrating.  Please fix, Google.
Sep 28, 2011
#125 n...@unitedweego.com
Droid2 testing device running 2.3.3 runs fine. Please fix emu.
Oct 5, 2011
#126 lloyd....@gmail.com
We're using phoneGap 1.0 and an app using file:/// based html files.
we had the problem of unwanted javscript "gap_poll:" prompts on Android phones and emulators.

We found the problem went away when we put all the files in one folder (the www folder).
Oct 24, 2011
#127 liuhongx...@gmail.com
unblievable
Oct 30, 2011
#129 huangfengjing
Fix it please, google.
It's a very serious bug.
Oct 31, 2011
#130 sui.dap...@gmail.com
It's really a critical bug, please fix it.
Nov 2, 2011
#131 pahan123
This critical bug has been there for almost a year and google is not showing any interest of fixing.  frustrating indeed
Nov 3, 2011
#132 dengk...@gmail.com
fuck google, it is real a serious bug.
Nov 11, 2011
#133 szabolcs...@gmail.com
Come on man, I don't believe it's unrepairable...
Nov 21, 2011
#134 markg...@gmail.com
This bug interacts badly with the ability to open ParcelFileDescriptor pipes (which requires Gingerbread) to provide additional content:// URL's for custom WebView content. The workaround isn't realistic for anything other than the most trivial triggers (i.e. you can't pass complex data structures back and forth). 


Nov 25, 2011
#135 miguel.m...@gmail.com
this bug is blocking, not just medium priority. fix this ASAP, google. your sells depends on customers being able to buy recent apps
Nov 29, 2011
#136 cdanie...@gmail.com
This is still an issue almost 1 year on.
I have an app I'd like to publish.
It will not work on 80-90% of devices. 4.0 is not out for updates yet and even then a small percentage of users with that version for the next year as the up_X work thru the system.

Nov 30, 2011
#137 ronh...@gmail.com
Experiencing the same problem.  This is a critical issue and needs to be fixed!
Dec 3, 2011
#138 nomadsh...@hotmail.com
Try mobilelite framework: https://code.google.com/p/mobilelite/
We have already solved this problem in the lightweight framework.
Dec 5, 2011
#139 Trenton....@gmail.com
Hmmm, Android is a nightmare for developers, NICE!  Things just don't get fixed I guess.  
Dec 12, 2011
#140 dmitry.k...@gmail.com
I have just implemented the fully synchronous workaround using WebViewChrome::onJsPrompt().

@Override
public boolean onJsPrompt(WebView view, String url,
		String message, String defaultValue,
		JsPromptResult result) {
	
	if(TextUtils.isEmpty(message) || !message.startsWith(SIGNATURE))
		return false;
	
	String json = message.substring(SIGNATURE.length());
	try{
		//It is our object
		JSONObject info = new JSONObject(json);
		JSONArray params = info.getJSONArray("params");
		int len = params.length();
		Object []paramValues = new Object[len];
		for(int i=0; i<len; ++i){
			Object obj = params.opt(i);
			paramValues[i] = obj;
		}
	
		Method method = ReflectionUtils.findOnlyMethod(api.getClass(), info.getString("method"));
		Object ret = method.invoke(api, paramValues);
		
		JSONObject res = new JSONObject();
		res.put("result", ret);
		result.confirm(res.toString());
	}catch(JSONException e){
		api.m_error_message = "Couldn't parse rpc call: " + json;
		result.confirm(null);
		return true;
	}catch(NoSuchMethodException e){
		api.m_error_message = "Can not find method: " + e.getMessage() + " on data " + json;
		result.confirm(null);
		return true;
	}catch(InvocationTargetException e){
		api.m_error_message = "Can not invoke method: " + e.getMessage() + " on data " + json;
		result.confirm(null);
		return true;
	}catch(IllegalAccessException e){
		api.m_error_message = "Can not access method: " + e.getMessage() + " on data " + json;
		result.confirm(null);
		return true;
	}
	return true;
}



On the javascript side it needs some changes as well, for example:

function callApiWorkaround(name, args){
  if(!args) args = [];
  var ret = prompt(g_api_signature + stringify({method: name, params: args}));
  if(ret && typeof ret == 'string'){
    ret = parse(ret);
    return ret.result;
  }
  return ret;
}

function api_trace(msg, callee){
  var method = 'trace';
  if(api)
    return api[method](msg, callee);
  return callApiWorkaround(method, [msg, callee]);
}
Dec 13, 2011
#141 dmitry.k...@gmail.com
With the workaround in comment 140 the only problem left is how to determine when it should be used instead of addJavaScriptInterface.

The comment 117 gives us a clue that it should be used when there is JSC on Gingerbread, but I don't think it's enough, because in comments 53, 54 they mentioned bugs on 2.2 phones. 
Dec 20, 2011
#142 r.kans...@gmail.com
Hi 
I am facing the same issue . Has anyone found a fix or workaround for this yet? Any help is appreciated.

Thanks 
Jan 9, 2012
#143 harish12...@gmail.com
Hi,

I'm facing with this issue but i got some what different info in my logcat i'm attaching here..For the total project i have used 2.3.3,so for maps also i used this but now i'm facing this issue.How can i over come this .please help me in solving this issue.
log.txt
1.3 KB   View   Download
Jan 11, 2012
#144 dmitry.k...@gmail.com
For those who lacks detailed solution, I present the more detailed one.
Say for calling simple toast function :

wb.addJavascriptInterface(new JavaScriptInterface(this), "Android");

In class JavaScriptInterface :
public void showToast(String toast) {
       Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}

suppose api is JavaScriptInterface implementation
wb is WebView
SIGNATURE is string constant defined by you to identify JSON RPC calls

First you need to implement WebChromeClient interface:

wb.setWebChromeClient(new WebChromeClient(){
    @Override
    public boolean onJsPrompt(WebView view, String url,
                    String message, String defaultValue,
                    JsPromptResult result) {

            if(TextUtils.isEmpty(message) || !message.startsWith(SIGNATURE))
                    return false;

            String json = message.substring(SIGNATURE.length());
            try{
                    // Это наш объект
                    JSONObject info = new JSONObject(json);
                    JSONArray params = info.getJSONArray("params");
                    int len = params.length();
                    Object []paramValues = new Object[len];
                    for(int i=0; i<len; ++i){
                            Object obj = params.opt(i);
                            paramValues[i] = obj;
                    }

                    Method method = ReflectionUtils.findOnlyMethod(api.getClass(),
                    		info.getString("method"));
                    Object ret = method.invoke(api, paramValues);

                    JSONObject res = new JSONObject();
                    res.put("result", ret);
                    result.confirm(res.toString());
            }catch(JSONException e){
                    api.m_error_message = "Couldn't parse rpc call: " + json;
                    result.confirm(null);
                    return true;
            }catch(NoSuchMethodException e){
                    api.m_error_message = "Can not find method: " + e.getMessage()
                    	+ " on data " + json;
                    result.confirm(null);
                    return true;
            }catch(InvocationTargetException e){
                    api.m_error_message = "Can not invoke method: " +
                    	e.getMessage() + " on data " + json;
                    result.confirm(null);
                    return true;
            }catch(IllegalAccessException e){
                    api.m_error_message = "Can not access method: " +
                    	e.getMessage() + " on data " + json;
                    result.confirm(null);
                    return true;
            }
            return true;
    }
});

//Now we can add javascript interface. In order to deal with gingerbread bug we can 
//check current API level and if it is Gingerbread just not add the interface.
//Or as in this case we can pass api level to javascript for it to determine if it should call
//prompt instead of javascript interface
wb.addJavascriptInterface(new JavaScriptInterface(this), "Android");


onJsPrompt uses ReflectionUtils.findOnlyMethod:

/**
 * Utilities for reflection.
 */
public class ReflectionUtils {
       private static Map<String, Set<Method>> METHOD_CACHE
               = new HashMap<String, Set<Method>>();

       private ReflectionUtils() { }
       /**
        * Finds methods with the given name on the given class.
        * @param clazz the class
        * @param name the method name
        * @return the methods
        */
       public static Set<Method> findMethods(Class<?> clazz, String name) {
               String cacheKey = clazz.getName().concat("::").concat(name);
               if (METHOD_CACHE.containsKey(cacheKey)) {
                       return METHOD_CACHE.get(cacheKey);
               }
               Set<Method> methods = new HashSet<Method>();
               for (Method method : clazz.getMethods()) {
                       if (method.getName().equals(name)) {
                               methods.add(method);
                       }
               }
               methods = Collections.unmodifiableSet(methods);
               METHOD_CACHE.put(cacheKey, methods);
               return methods;
       }

       /**
        * Finds methods with the given name on the given class.
        * @param clazz the class
        * @param name the method name
        * @return the methods
        * @throws NoSuchMethodException
        */
       public static Method findOnlyMethod(Class<?> clazz, String
name) throws NoSuchMethodException {
               Set<Method> set = findMethods(clazz, name);
               if(set.size() != 1)
                       throw new NoSuchMethodException(name + " zero or not
exactly one");
               return set.iterator().next();
       }
}

So the java part is done. Now let's make changes to the client.
Instead of just calling
Android.showToast('something') make the following:

var g_api_signature = 'SIGNATURE value from java part';
var g_api_androidAPI = 9; //This should be set to current 
//android API level somehow from java part

var AndroidAPI = function(){
   function isJSC(){
       //You can determine which JS engine is in use at runtime through
       //the following javascript snippet:
       //(from https://code.google.com/p/android/issues/detail?id=12987#c117)
               return window.devicePixelRatio &&
                       escape(navigator.javaEnabled.toString()) !==
                       'function%20javaEnabled%28%29%20%7B%20%5Bnative%20code%5D%20%7D';
   }

   function isGingerbread(){
       var androidAPI = g_api_androidAPI;
               return 9 <= androidAPI && androidAPI <= 10;
   }

   function shouldUseGingerbreadWorkaround(){
       //The addJavaScriptInterface is encountered on gingerbread with
       //JSC javascript engine
       //So use workaround
       return isGingerbread() && isJSC();
   }

   function ApiSystemError(msg){
       this.name = 'AndroidApiError';
       this.message = msg;
   }

   var api = shouldUseGingerbreadWorkaround() ? null : window.Android,
       stringify = JSON.stringify, //You should also include json2.js
       parse = JSON.parse; //from https://github.com/douglascrockford/JSON-js

   function callAndroid(name, args){
       if(!args) args = [];
       var ret = promptfunc(g_api_signature + stringify({method: name,
                            params: args}));
       if(ret && typeof ret == 'string'){
               if(ret.charAt(0) == '{'){
                       ret = parse(ret);
                       return ret.result;
               }else{
                       //Error, a JSON object should have returned
                       throw new ApiSystemError(ret);
               }
       }else{
               throw new ApiSystemError('Api returned nothing!');
       }
   }

   /* the api_xxx functions are workaround for gingerbread bug *
    * https://code.google.com/p/android/issues/detail?id=12987 */
   function api_showToast(str){
       var method = 'showToast';
       //Please note that it is not even necessary for javascript 
       //interface to be really added. In such case we just call
       //Java through prompt
       if(api) 
               return api[method](str);
       return callAndroid(method, [str]);
   }

   return {
       showToast: function(str){
           return api_showToast(str);
       }
   };

}();

//Safely show Toast:
AndroidAPI.showToast('something');

Well, something like that. Enjoy.
Jan 24, 2012
#145 garg872@gmail.com
@ comment 144:
I have tried the code you have posted above, i am getting some other errors..
 and what is "api" in java code..
Can you please attach a sample project where you have enabled this??

Thanks,
Deepak K Garg
gargengineer.blogspot.com


Jan 31, 2012
#146 arusahni
Here's a workaround that has worked for me with minimal pain: http://stackoverflow.com/questions/7424510/uncaught-typeerror-when-using-a-javascriptinterface 
Feb 3, 2012
#147 julianro...@gmail.com
So, I assume this has still not been fixed judging by the recent activity.

In summary...

I still get this error on 2.3.1 and 2.3.3 emulators. 

However does it actually affect 2.3.3 devices? There seems to be some dispute in the thread about whether it does or not.
Feb 15, 2012
#148 ulrik.so...@gmail.com
What a Terrible Failure (WTF)
Please fix asap
Feb 22, 2012
#149 agleb...@gmail.com
fatality... mortality... bugality!
Please fix it
Mar 1, 2012
#150 toritonD...@gmail.com
Any news about this issue?
I'm experiencing the same problem with 3.1 and 4.0 version.


Mar 8, 2012
#151 harryz...@gmail.com
I also get this error on android 2.3.3 emulators. 
Mar 12, 2012
#152 anderson...@gmail.com
Just got this error on android 2.3.3 emulators too.
Mar 21, 2012
#153 hoangdat...@gmail.com
[2012-03-22 11:02:48 - LogCatFilter] Ignoring invalid text regex.
[2012-03-22 11:02:48 - LogCatFilter] Dangling meta character '*' near index 0
*:S
^
I also get this error on android 2.3.3 emulators and htc wildfire S
Apr 5, 2012
#154 maurun...@gmail.com
I also get this error on android 2.3.3 emulator on Windows 7 Japanese.
(BTW, my au/KDDI IS03 (Android 2.2.1) do not get this error)

Apr 8, 2012
#155 bobxi...@gmail.com
i wonder whether the issue was fixed 
Apr 9, 2012
#156 voicemor...@gmail.com
FIXED!!!PLS!!! Google!!!
Apr 19, 2012
#159 henrikk...@gmail.com
I can reproduce this on Galaxy Nexus 


bug.txt
35.9 KB   View   Download
Apr 22, 2012
#160 dalewk...@gmail.com
I wasted half a day trying to figure out why code that ran fine in 1.6 was crashing in 2.3.3 emulator.
May 1, 2012
#161 doughill...@gmail.com
I re-ran into this issue today. What is shameful is that it has been 18 months since the issue was reported with apparently no fix or response from the Android team.  (If there is a response, please link to it here).  If only a small fraction of Android devices were still running 2.3.x then this problem would be a non-issue.  This obviously isn't the case. 
May 9, 2012
#162 junk643...@gmail.com
GGGGGGGGGG OOOOOOOOOOOOOO OOOOOOOOOOOOOOOO GGGGGGGGGGGGGGG LLLLLLLLLLLLLL EEEEEEEEEEEE

Android 2.3 is still VERY relevent and this is f@#!ing pathetic!

Keep the hate mail coming, the tipping point may be near!

May 13, 2012
#163 elvin...@gmail.com
its too risky to use javascriptinterface callback since there are many device with os 2.3.+ around. 

so i avoided it and used the html "a href" calling to pass back the data from my webview to the activity and process it there on. I used a webviewclient to listen to the called url and perform my stuff accordingly based on the url.

my codes are as below hope someone can comments or point out any weakness in it.
before that, sorry for my bad written english.


onCreate section:

WebView myWebView= (WebView) findViewById(R.id.myWebview);
myWebView.setWebViewClient(new myWebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
String myHTML  = "<html><body><a href='androidcall01|123456'>Call Back to Android 01 with param 123456</a>my Content<p>my Content<p>my Content<p><a href='androidcall02|7890123'>Call Back to Android 01 with param 7890123</a></body></html>";
myWebView.loadDataWithBaseURL("about:blank", myHTML, "text/html", "utf-8", "");


Webview client utilize shouldOverrideUrlLoading:-

private class myWebViewClient extends WebViewClient {
   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //Toast.makeText(getBaseContext(), "shouldOverrideUrlLoadin url: " + url, Toast.LENGTH_SHORT).show();
        StringTokenizer st = new StringTokenizer(url, "|");
        String function = st.nextToken();
        String parameter = st.nextToken();
        if ( function.equalsIgnoreCase("androidcall01") ) {
           Toast.makeText(getApplicationContext(), "android call 01 value received: " + parameter, Toast.LENGTH_SHORT).show();
           // do your stuff here.....
           return true;
        } else if ( function.equalsIgnoreCase("androidcall02") ) {
           Toast.makeText(getApplicationContext(), "android call 02 value received: " + parameter, Toast.LENGTH_SHORT).show();
           // do your stuff here.....
           return true;   
        } else {
           // its not an android call back 
           // let the browser navigate normally
           return false;
        }
   }   
}  
Jul 2, 2012
#164 ANDROID1...@gmail.com
Can anyone verify here that the javascript bridge has been fixed post-gingerbread? Can we assume business as usual on honeycomb and ics? 
Jul 10, 2012
#165 roygree...@gmail.com
I still get error on android 2.3.3 emulator......
Aug 29, 2012
#166 viet...@gmail.com
Rather than an application level workaround, does anybody know of a framework/webkit fix for this issue? 
Aug 30, 2012
#167 Yuri.Iva...@gmail.com
2 years and the issue is still reproducible...
Sep 10, 2012
#168 bulentke...@gmail.com
i have got error on android 2.1
Sep 26, 2012
#169 r...@mugeda.com
I got same issue on both 2.3.3 emulator and real phone(Motorola 2.3.3).
Sep 27, 2012
#170 jonathan...@gmail.com
Clearly not fixed - got error on 2.3.3 AVD - I am wondering why this has not been fixed yet , it seems critical. 
Oct 2, 2012
#171 rene.har...@gmail.com
Still not fixed on 2.3.3 emulator
Oct 2, 2012
#172 rene.har...@gmail.com

I just got the example of comment 140 to work, it was the best solution I could find for now...

In response to comment 145: 'api' should be an instance of the JavaScriptInterface class:

public JavaScriptInterface api = new JavaScriptInterface(this);

This object has to be reachable from within the onJsPrompt function.

I removed all references from 'api' to 'm_error_message', but if you do want to use this you have to add this property to your JavaScriptInterface class or else it will not build.

Another thing is that the Javascript part of the example uses a function called 'promptfunc'. You have to replace this with 'prompt'. This will invoke the onJsPrompt function declared in Java. 
Oct 2, 2012
#173 rafal.ry...@gmail.com
For anyone who encounter this issue dealing with GWT application - in my case the workaround was to use Scheduler.get().scheduleDeferred(...) for the problematic instruction. I suppose for pure JavaScript app setTimeout() might be useful.
Nov 7, 2012
#174 avrazgu...@gmail.com
wanted to express thanks to dmitry.k (comment 140) for the workaround. Although it still won't work in my case, as I am trying to simulate function calls into javascript that return values. Using the broken JavaScriptInterface it was possible to do it by busy-waiting, but the same trick will work with the onJsPrompt.
Nov 8, 2012
#175 roninsof...@gmail.com
I'm just wondering what is wrong in your guys' development and QA process that so many fatal bugs make it through your releases. How come Mobile Safari gets it right, but you guys can't? You're building a platform for thousands of developers running on millions of phones for f#43 sake!! You are the IE6 of mobile!!!
Dec 11, 2012
#176 JUNNEL1...@gmail.com
I just want to know if the problem is on the emulator only? Is it also crashed on real devices??
Dec 18, 2012
#177 ata.meta...@gmail.com
I've the same problem, I'm working on Android 4.0.3 on real device.
Dec 22, 2012
#179 yacirhus...@gmail.com
Thanks 140 for workaround :)
Jan 9, 2013
#180 Samuel.E...@gmail.com
This is completely and utterly ridiculous that a patch has not been released for this
Jan 9, 2013
#181 Samuel.E...@gmail.com
163 is the best workaround. Thank god for this.
Jan 20, 2013
#182 cory.tr...@gmail.com
I'm just wondering what is wrong in Google's development and QA process that so many fatal bugs make it through to production releases.
Jan 21, 2013
#183 Mr.Sorl...@gmail.com
thanks a lot!!! 144 and 172 workaround solved the issue for me :-)
Feb 4, 2013
#184 rok.ar...@gmail.com
I get this error on the 2.3 simulator while loading ads from inneractive (and some other ad providers). Is there any way to detect, if the device supports V8 Engine from Java code?

This way, I could just load ads from another provider for this few devices.

About 32% of my users still have 2.3.x devices.
Feb 8, 2013
#185 tsoints...@gmail.com
it's a shame
Feb 19, 2013
#186 nguyen.t...@gmail.com
This issue happened only on 2.3.3 emulator. It works on 4.0 and above emulators/devices.

Too bad I don't have a 2.3.3 device to test...
Feb 20, 2013
#187 haenl...@gmail.com
Woah, reported in 2010, now we have 2013 and still this isn't fixed.
Shame on you, Google.
Mar 6, 2013
#188 Christop...@gmail.com
Since this is only on 2.3.3 I'm guessing at this point the estimated risk of losing business/upsetting developers outweighs the cost of fixing a bug almost 2 versions old. 
Mar 20, 2013
#190 patr...@appade.com
This is just another example of Google's web beta mentality where the end-users beta test their code.  The problem is on Android, these bugs stick around forever on low-end Android handsets that never get updated.  The poor suffering masses on Android developers must forever work-around Google's bugs because we can't just move onto the next release on Android like they do.  One of my biggest clients is in the Czech Republic and the most popular Android handsets in the Czech Republic have this bug.
Apr 1, 2013
#191 m...@gladesoft.com
I can't believe a major piece of functionality like this is completely broken. Sadly it's far from the only major API in Android that is completely non-functional.

Apr 5, 2013
#193 SIDDHART...@gmail.com
	if (android.os.Build.VERSION.SDK_INT > 9) {
		    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		    StrictMode.setThreadPolicy(policy);
		}


It is to be added for sdk versions more than 9 or 9 

I hope this helps

Add this code in on Create method 

this code should be placed fist in on create means it should be executed first


If it gives error than suppress warnings . 
Jun 19, 2013
#196 jbq@android.com
(No comment was entered for this change.)
Status: Assigned
Mar 8, 2014
Project Member #197 al...@android.com
(No comment was entered for this change.)
Status: Unassigned
Sign in to add a comment

Powered by Google Project Hosting