Search code examples
javascripthtmlgoogle-play-servicesgoogle-play-gamescrosswalk-runtime

Possible to use Google Play Game Services from origin file:///android_asset


Crosswalk is an excellent wrapper to allow HTML5 games to be packaged as native Android apps. You upload your HTML, JS and CSS files and it wraps it with Chromium for Android and builds an APK. It has full GPU support including WebGL, making it far better than PhoneGap.

I want to use the Google Play Game Services web API in a Crosswalk app, but it appears Crosswalk runs from the origin file:///android_asset. E.g. the main page will run from file:///android_asset/www/index.html.

It does not appear possible to allow Crosswalk apps to use the web API. The API console rejects file:///android_asset as an "invalid URI". Is there any workaround to this? Crosswalk is the only sensible way to publish HTML5 games as native apps on Android, and it's a shame if we can't use Google Play services!


Solution

  • The JavaScript code is limited by the same-origin policy, so you cannot access the Google play services(https://www.googleapis.com/*) from the origin file:///android_asset. But Crosswalk has provided the solution for the cross-origin xhr, you can easily achieve that via adding the following configure to the manifest of your app.

    {
      ...
      "xwalk_hosts": [
        "http://www.host-you-want-to-go.com/*"
      ],
      ...
    }
    

    More details in wiki.

    You must try it in the latest beta version of Crosswalk, 6.35.131.5.

    You can also ask the help about Crosswalk on the [email protected], in which you could get more faster response.