cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Bowser <bows...@gmail.com>
Subject Re: addJavascriptInterface fails on Android API levels 17 and 18 (4.2.2 and 4.3)
Date Wed, 11 Sep 2013 23:59:41 GMT
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
Interface.

On Wed, Sep 11, 2013 at 4:52 PM, dev at watch2web.com <dev@watch2web.com> wrote:
> 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");
>
> window.MyJSI.foo();  // 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.
>
> https://issues.apache.org/jira/browse/CB-1879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501660#comment-13501660
>
>
> 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

Mime
View raw message