Ammo wasm fails to compile on native build

Im using Xamarin to export an apk from a game, and the ammo library fails to compile.

Im wondering if I have to “import ammo” at all or if the basics of the physics are already in the Playcanvas source?

Here’s the log

[INFO:CONSOLE(21)] “Fetch API cannot load file:///android_asset/files/assets/29228944/1/ammo.wasm.wasm. URL scheme “file” is not supported.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
03-25 18:40:41.449 I/chromium(18725): [INFO:CONSOLE(21)] “Fetch API cannot load file:///android_asset/files/assets/29228944/1/ammo.wasm.wasm. URL scheme “file” is not supported.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
[INFO:CONSOLE(21)] “wasm streaming compile failed: TypeError: Failed to fetch”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
03-25 18:40:41.634 I/chromium(18725): [INFO:CONSOLE(21)] “wasm streaming compile failed: TypeError: Failed to fetch”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
[INFO:CONSOLE(21)] “falling back to ArrayBuffer instantiation”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
03-25 18:40:41.645 I/chromium(18725): [INFO:CONSOLE(21)] “falling back to ArrayBuffer instantiation”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (21)
[INFO:CONSOLE(19)] “Fetch API cannot load file:///android_asset/files/assets/29228944/1/ammo.wasm.wasm. URL scheme “file” is not supported.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (19)
03-25 18:40:41.657 I/chromium(18725): [INFO:CONSOLE(19)] “Fetch API cannot load file:///android_asset/files/assets/29228944/1/ammo.wasm.wasm. URL scheme “file” is not supported.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (19)
[INFO:CONSOLE(292)] “both async and sync fetching of the wasm failed”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
[INFO:CONSOLE(292)] “both async and sync fetching of the wasm failed”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
03-25 18:40:41.662 I/chromium(18725): [INFO:CONSOLE(292)] “both async and sync fetching of the wasm failed”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
03-25 18:40:41.664 I/chromium(18725): [INFO:CONSOLE(292)] “both async and sync fetching of the wasm failed”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
[INFO:CONSOLE(20)] “failed to asynchronously prepare wasm: abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (20)
03-25 18:40:41.679 I/chromium(18725): [INFO:CONSOLE(20)] “failed to asynchronously prepare wasm: abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (20)
03-25 18:40:41.680 I/chromium(18725): [INFO:CONSOLE(292)] “abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
[INFO:CONSOLE(292)] “abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
[INFO:CONSOLE(292)] “abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
03-25 18:40:41.682 I/chromium(18725): [INFO:CONSOLE(292)] “abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/files/assets/29228946/1/ammo.wasm.js (292)
[INFO:CONSOLE(0)] “Uncaught (in promise) abort(“abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/index.html (0)
03-25 18:40:42.063 I/chromium(18725): [INFO:CONSOLE(0)] “Uncaught (in promise) abort(“abort(“both async and sync fetching of the wasm failed”). Build with -s ASSERTIONS=1 for more info.”). Build with -s ASSERTIONS=1 for more info.”, source: file:///android_asset/index.html (0)

Update, just found out that in webview Im unable to use xmlhttprequest and the ammo.js uses it to compile - any ideas?

Hi @Yohami_Zerpa,

I think if the xmlhttprequest object isn’t available at all, you will have a hard time loading any Playcanvas project. All assets are using it to get loaded.

@Leonidas what is the difference between importing ammo vs not doing it?

The projects in tutorial don’t import ammo https://developer.playcanvas.com/en/tutorials/collision-and-triggers/ they also compile fine on the Xamarin

But I’ve always had ammo installed, Im wondering if things will break by taking it out

@Leonidas I removed ammo from my project but effectively I’ve got no physics now - but this one does without importing ammo https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

Is there a setting to enable built in physics without importing?

So from studying your log, the issue isn’t that xmlhttprequests aren’t supported but the .wasm file is not supported (Web Assembly).

Ammo isn’t integrated in Playcanvas engine, so you have to import using either a the .wasm loader or, if Web Assembly is not supported, the legacy .js Ammo script.

Take a look at this example on how it adds a check (wasmSupported) to provide a fallback on non supported environments. You can implement something similar in your app:

If you would like to go quick and dirty :slight_smile: (for testing) you can just add the following link to your HTML file. This will load an older version of Ammo, same used in the collision-and-triggets example:

https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/Ksj3sLXk/ammo.dcab07b.js

The legacy version seems to work, thanks - I’ll do some research on loading webassembly on webview / xamarin

2 Likes