Question

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!

Was it helpful?

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 crosswalk-help@lists.crosswalk-project.org, in which you could get more faster response.

OTHER TIPS

I wrote a simple example that accesses google play game services with cordova and crosswalk. See https://github.com/rscohn2/phonegapi With cordova, you can create a browser window for the login, and give http://localhost as the redirect URI. After a successful login, it redirects to http://localhost, which is not present. The app detects that the browser window has redirected. It reads the access code, then closes the window before the user can see the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top