抱歉,该网页目前还不存在中文版本,请继续浏览其他网页!

Remote debugging

Web applications running under Crosswalk can be debugged remotely using the Chrome dev tools.

Note that to debug a Crosswalk application with Chrome, you must ensure that your Chrome version is appropriate for the version of Crosswalk you are using. See this wiki page, which shows the mapping between Crosswalk and Chrome versions for debugging.

On Android, the connection between the host and target is established using adb. You will need to ensure that you have installed the Android SDK (instructions for Windows and Linux) so that this tool is available.

You will also need to set up an Android target and install a packaged Crosswalk application on it. See these instructions.

Debugging on Android can be enabled in two ways: at build time and at run time. Both options are described below.

Enable debugging at build time for Android

Once the pre-requisites have been met, debug your Crosswalk application as follows:

  1. Enable remote debugging of your app. This depends on how you are using Crosswalk:

    • Generating an Android package using make_apk.py

      Enable remote debugging by passing a flag to make_apk.py when building the package. For example:

      $ python make_apk.py --package=org.crosswalkproject.example \
        --manifest=/home/me/myapp/manifest.json --enable-remote-debugging
    • Embedding Crosswalk in your application via the embedding API

      Modify your application's main activity to set the remote debugging preference. For example:

      XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);

      Then build the application package the usual way (e.g. using Ant or ADT).

      Full details are given in the Crosswalk embedding tutorial.

    • Using a Cordova application migrated to Crosswalk

      When you build a Cordova application which has been migrated to Crosswalk, remote debugging is enabled by default. You shouldn't have to do anything other than the usual build:

      $ cordova build android

      Install and run the application as usual, for example:

      $ cordova run android

      Remote debugging can be disabled by passing the --release option to the build.

    • Using an application created using Crosswalk Cordova

      Remote debugging is enabled by default when you build an application created with Crosswalk Cordova. For example:

      $ ./cordova/build

      will build an application with remote debugging turned on.

  2. Install and run the application on the target, using your preferred tool (for example, adb).
  3. On the host, open a Chrome browser and go to "chrome://inspect" in the address bar. This should show a list of attached devices, with your application listed, for example:

    Debugging a Crosswalk application in Chrome

    (The application available for debugging is highlighted with a red box in the image.)

    Click on the "inspect" link to open the application for debugging with the Chrome dev tools.

Enable debugging at run time for Android

Note: The instructions below only work with Crosswalk version 10 and lower.

Starting with Crosswalk version 11, the ability to turn on debugging at run time was disabled for security purposes.

If you built your Android package without the debugging feature, you can still turn on the feature at run time by sending it an intent. This works for a Crosswalk application built using any of the packaging methods, i.e.

  1. Packaged with make_apk.py.
  2. Using the Crosswalk embedding API.
  3. Migrated from Cordova.
  4. Created using Crosswalk Cordova.

Note that the intent will enable remote debugging feature for all Crosswalk applications which are running on the target.

First ensure that the pre-requisites have been met. Then follow these steps to enable remote debugging for Crosswalk applications:

  1. Install and run the application(s) on the target, using your preferred tool (for example, adb).

  2. From the host, use adb to broadcast the remote debugging intent to all Crosswalk applications on the target:

    $ adb shell am broadcast -a org.xwalk.intent -e remotedebugging true
  3. On the host, open a Chrome browser and go to "chrome://inspect" in the address bar. This should show a list of attached devices, with your application listed, for example:

    Debugging a Crosswalk application in Chrome

    (The application available for debugging is highlighted with a red box in the image.)

  4. Click on the "inspect" link to open the application for debugging with the Chrome dev tools.

Note that it is also possible to disable remote debugging using the same intent, with:

$ adb shell am broadcast -a org.xwalk.intent -e remotedebugging false

Troubleshooting

  • adb can't connect to the device

    You may occasionally find that adb is unable to connect to the device, and remote debugging won't work. You can try unplugging the USB cable between your host and target (if using a USB connection), then reattaching it, which sometimes fixes the issue; or you could try running adb as root.

  • The application doesn't appear in the chrome://inspect page

    If the application is not visible in the inspection page, use adb to check that remote debugging is enabled for the application:

    host$ adb shell
    shell@android$ cat /proc/net/unix |grep devtools_remote
    00000000: 00000002 00000000 00010000 0001 01 1102698 @org.crosswalkproject.app_devtools_remote
    00000000: 00000002 00000000 00010000 0001 01 1092981 @org.xwalk.core.xwview.shell_devtools_remote

    If you cannot see any entries ending with _devtools_remote, it's likely that remote debugging is not enabled for the application. Follow the steps above to either rebuild the application with remote debugging support, or switch remote debugging on at run time.

Further information

For information about using the Chrome dev tools for debugging, see this page.