cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "dev at" <>
Subject Re: addJavascriptInterface fails on Android API levels 17 and 18 (4.2.2 and 4.3)
Date Thu, 12 Sep 2013 07:00:14 GMT
My app is a Cordova app -- Cordova 3.0.0, as I said. I added just a few 
little JavascriptInterface methods because they did so little that writing a 
full-on plugin seemed like overkill. It has all worked very nicely until API 
17, and I have not come across something that says it is forbidden to create 
your own little JSI when using Cordova. If it is forbidden, please tell me, 
and I apologize for my ignorance.

I am using JDK 1.6. According to docs, it has full support for annotations, 
and if it didn't, wouldn't this have failed on API levels 16 and lower?

I guess your point is that I can probably demonstrate the same failure in an 
app that doesn't use Cordova, and therefore, my problem is irrelevant. You 
may be right about the first part, and of course I respect your judgment re. 
relevance. But I imagine the same thing could be said about a lot of issues 
you have had to deal with. I was hoping to get some direction from experts 
who have had to deal with whatever change in Android 4.2.2 (API 17) occurred 
that seems to be connected here.

----- Original Message ----- 
From: "Joe Bowser" <>
To: "dev" <>
Sent: Wednesday, 11 September, 2013 16:59
Subject: Re: addJavascriptInterface fails on Android API levels 17 and 18 
(4.2.2 and 4.3)

What does this have to do with Cordova? It looks like you're building
your own bridge on Android.

Make sure that your Java version that you're building with supports
annotations. If not, you won't be able to add the Javascript

On Wed, Sep 11, 2013 at 4:52 PM, dev at <> 
> I recently changed the value of targetSdkVersion in my AndroidManifest.xml 
> from 16 to 18. They say, "Better late than never," but maybe not in this 
> case. I discovered that the change causes my app to white-screen on 
> startup on two Samsung Galaxy S4s -- both running API level 17 (4.2.2). 
> (On the five other devices I have -- all running API 16 or lower --  
> everything still works as if nothing has changed.) If I set 
> targetSdkVersion back to 16, the app works great on all devices, including 
> both Samsungs. I am using Cordova 3.0.0.
> I have traced the problem to my onDeviceReady function, at the line where 
> it first tries to execute one of my @JavascriptInterface functions. (It 
> doesn't seem to matter which one.) Code snippet looks like:
> (in main Activity)
> appView.addJavascriptInterface(this, "MyJSI");
> @JavascriptInterface
> public void foo() { .... }
> (in onDeviceReady)
> if (window.MyJSI == undefined) console.log("javascript interface is 
> undefined");
> else if (window.MyJSI == null) console.log("javascript interface is 
> null");
> else if (typeof(window.MyJSI) == 'object') console.log("javascript 
> interface is an object: " + window.MyJSI);
> else console.log("javascript interface is not an object");
>;  // foo is just some method I wrote -- I've only 
> experimented with a few
> On both "good" (API level <= 16) and "bad" (Galaxy S4, API level >= 17) 
> phones I get in the console output:
>>> javascript interface is an object: [object Object]
> On the "good" phones, everything continues, and I get all the logging that 
> comes from subsequent parts of the app. On the "bad" phone, I get:
>>> Uncaught TypeError: Object [object Object] has no method 'foo'
> and things pretty much stop.
> You'd think I was in OK shape. I have a fix that involves changing one 
> character -- not even in code, just a settings file -- and it works on all 
> API levels. But NO, Google Play forbids lowering the targetSdkVersion. So 
> I need to fix this for real.
> In searching, I found this issue from December. It isn't exactly what I'm 
> seeing since deviceready does fire for me. But a lot of the elements seem 
> very similar.
> I'm happy to dig through Java source myself if it will help, but if so, I 
> could use a little guidance getting started.
> Thanks,
> Andrew

View raw message