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

Building a Crosswalk application

Crosswalk is a runtime for HTML5 applications. This means that any existing HTML5 applications should run on Crosswalk, providing they already run in a modern browser (Chrome, Firefox, Safari).

For the purposes of this tutorial, we use the simplest possible Crosswalk application: one HTML file.

However, because Crosswalk applications are intended to integrate well with the target environment, they require an additional file, manifest.json, containing metadata for that purpose. The manifest can be used to specify icons to use at different resolutions, set an app description, adjust content security policy settings, and otherwise configure how the app integrates with the target environment.

A simple application

  1. First, create a directory called xwalk-simple for the project:

    > mkdir xwalk-simple/
    > cd xwalk-simple/
  2. Next, copy an icon file to that directory, to serve as the application icon. You can use this image:

    To use this example, right click on the image and select Save Image As... (or its equivalent in your browser). Save it into the xwalk-simple directory as icon.png. (Note that this image is from the Crosswalk source code and is BSD licensed.)

    If you have your own favourite icon, copy that to the xwalk-simple directory instead. It should be 128 pixels square.

  3. Create two text files inside xwalk-simple (create them using any text editor, e.g. Notepad on Windows, gedit on Ubuntu):

    1. index.html

      This is a single HTML file which represents the user interface for the application. For the purposes of this tutorial, we are not using any CSS or JavaScript.

      The content should be:

      <!DOCTYPE html>
      <html>
        <head>
          <meta name="viewport"
                content="width=device-width, initial-scale=1.0">
          <meta charset="utf-8">
          <title>simple</title>
        </head>
        <body>
          <p>hello world</p>
        </body>
      </html>
    2. manifest.json

      This contains the application metadata (see above).

      The content should be:

      {
        "name": "simple",
        "xwalk_version": "0.0.1",
        "start_url": "index.html",
        "icons": [
          {
            "src": "icon.png",
            "sizes": "128x128",
            "type": "image/png",
            "density": "4.0"
          }
        ]
      }

      See the manifest documentation for more information.

Once you've done this, you're ready to run the application on a target.