Apache Cordova
  1. Apache Cordova
  2. CB-1879

DeviceReady event not firing on Nexus 7 4.2 emulator on a PC

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: Android
    • Labels:
      None

      Description

      I created an application with the create.bat on windows and compiled it with ADT and the latest SDK.

      It launches and displays the cordova display but it doesnt fire the deviceready event as it keeps saying "connecting to device". The same applies for the emulator. It works when I change the OS to 4.0 for the emulator though.

      I think this is just an emulator problem but I'm waiting to hear back from someone with a real device.

        Activity

        Hide
        Joe Bowser added a comment -

        Same here. I got crazy compile errors. I think I tweeted a bunch of profanity related to this.

        Show
        Joe Bowser added a comment - Same here. I got crazy compile errors. I think I tweeted a bunch of profanity related to this.
        Hide
        Simon MacDonald added a comment -

        Weird, when I added that annotation in Eclipse and Ant complained. I was using Android SDK 17. But now after getting your change it works fine. I'm not going to waste any more time wondering about it though.

        Show
        Simon MacDonald added a comment - Weird, when I added that annotation in Eclipse and Ant complained. I was using Android SDK 17. But now after getting your change it works fine. I'm not going to waste any more time wondering about it though.
        Show
        Andrew Grieve added a comment - Committed this: https://git-wip-us.apache.org/repos/asf?p=cordova-android.git;a=commit;h=3566154cd02b10cc1fb5dde39db30a02dc56a953
        Hide
        Andrew Grieve added a comment -

        I didn't test this out, but according to the docs, this should only break on 4.2 devices if the app was compiled to target API level 17 (JB-MR1). No existing apps should be broken.

        Did you say you found a compile error when trying to add @JavascriptInterface to the methods? I did so in this branch:

        https://github.com/agrieve/incubator-cordova-android/commit/144d986de97592a92e162c389fb071449c737f7d

        And it compiled & ran fine on my 4.2 Galaxy Nexus.

        Show
        Andrew Grieve added a comment - I didn't test this out, but according to the docs, this should only break on 4.2 devices if the app was compiled to target API level 17 (JB-MR1). No existing apps should be broken. Did you say you found a compile error when trying to add @JavascriptInterface to the methods? I did so in this branch: https://github.com/agrieve/incubator-cordova-android/commit/144d986de97592a92e162c389fb071449c737f7d And it compiled & ran fine on my 4.2 Galaxy Nexus.
        Show
        Joe Bowser added a comment - Fixed by adding an else-if in Java. The less changes to the JS, the better. https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-js.git;a=blobdiff;f=lib/android/exec.js;h=c6e426fd8a496fac814c23b295359fc947f875cb;hp=bbc66ccfb8cc76f136e56c01bdfbb390949a5026;hb=48d5bb1be59e5f0a4df3e896788b40bca35b3d69;hpb=13840a8cdfffe20130461fe3a26e93b2ac9b93fa https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=commit;h=c416c77d7a53c8efb2275e147c4f91caac71a334
        Hide
        Joe Bowser added a comment -

        Switching to Java Fix

        Show
        Joe Bowser added a comment - Switching to Java Fix
        Hide
        Joe Bowser added a comment -

        I guess we can use this and I can revert the last JS change.

        Show
        Joe Bowser added a comment - I guess we can use this and I can revert the last JS change.
        Hide
        Joe Bowser added a comment -

        Fixed by switching to prompt on Cordova JS. The annotations are broken so we can't use AddJavascriptInterface.

        https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-js.git;a=commit;h=13840a8cdfffe20130461fe3a26e93b2ac9b93fa

        Show
        Joe Bowser added a comment - Fixed by switching to prompt on Cordova JS. The annotations are broken so we can't use AddJavascriptInterface. https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-js.git;a=commit;h=13840a8cdfffe20130461fe3a26e93b2ac9b93fa
        Hide
        Simon MacDonald added a comment -

        Hey Joe, Tom posted a patch to SO.

        http://stackoverflow.com/questions/13433656/phonegap-not-firing-deviceready-on-android-4-2/13455618#13455618

        Folks are reporting that it is working. Maybe we can check that in for now and work on the refactor.

        Show
        Simon MacDonald added a comment - Hey Joe, Tom posted a patch to SO. http://stackoverflow.com/questions/13433656/phonegap-not-firing-deviceready-on-android-4-2/13455618#13455618 Folks are reporting that it is working. Maybe we can check that in for now and work on the refactor.
        Hide
        Joe Bowser added a comment -

        Figured it out myself. Switching to prompt for all input, because the annotation doesn't compile with the current SDK installed.

        Show
        Joe Bowser added a comment - Figured it out myself. Switching to prompt for all input, because the annotation doesn't compile with the current SDK installed.
        Hide
        Joe Bowser added a comment -

        We need to go back to prompt. addJavascriptInterface changes on 4.x require a refactor of the code to work right.

        Show
        Joe Bowser added a comment - We need to go back to prompt. addJavascriptInterface changes on 4.x require a refactor of the code to work right.
        Hide
        Joe Bowser added a comment - - edited

        I can reproduce on this end, but this is not a blocker. 4.2 is only on the Nexus 4, 7 and 10. It's major because a lot of people have the Nexus 7 and ordered the 4, but they aren't the majority of devices.

        Show
        Joe Bowser added a comment - - edited I can reproduce on this end, but this is not a blocker. 4.2 is only on the Nexus 4, 7 and 10. It's major because a lot of people have the Nexus 7 and ordered the 4, but they aren't the majority of devices.
        Show
        Marcel Kinard added a comment - FYI, A couple of docs I found: http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29 http://developer.android.com/reference/android/webkit/JavascriptInterface.html
        Hide
        Simon MacDonald added a comment -

        I changed the priority to blocker. When I originally opened the bug it was only reproducible on a emulator on a PC. Now that we have confirmations of problems on devices I've upped the priority.

        Show
        Simon MacDonald added a comment - I changed the priority to blocker. When I originally opened the bug it was only reproducible on a emulator on a PC. Now that we have confirmations of problems on devices I've upped the priority.
        Hide
        Tom Clarkson added a comment -

        Definitely not just an emulator issue - I'd classify it as blocker rather than minor.

        The problem seems to be a change in 4.2:

        WebView.addJavascriptInterface requires explicit annotations on methods for them to be accessible from Javascript.

        I was able to get deviceready firing again by excluding 4.2 in CordovaWebView.exposeJsInterface(). The proper solution is probably to work out what those annotations are, but any side effects that the quick fix may have are less severe than the app failing to start.

        Show
        Tom Clarkson added a comment - Definitely not just an emulator issue - I'd classify it as blocker rather than minor. The problem seems to be a change in 4.2: WebView.addJavascriptInterface requires explicit annotations on methods for them to be accessible from Javascript. I was able to get deviceready firing again by excluding 4.2 in CordovaWebView.exposeJsInterface(). The proper solution is probably to work out what those annotations are, but any side effects that the quick fix may have are less severe than the app failing to start.
        Hide
        Joe Bowser added a comment -

        DeviceReady fired when I tested 4.2 on Friday. I blame the emulator for being too slow and screwing something up. People should wait on Intel to create an image. The ARM one is too slow.

        Show
        Joe Bowser added a comment - DeviceReady fired when I tested 4.2 on Friday. I blame the emulator for being too slow and screwing something up. People should wait on Intel to create an image. The ARM one is too slow.

          People

          • Assignee:
            Joe Bowser
            Reporter:
            Simon MacDonald
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development