繁体   English   中英

如何在 React-Native 中加载 .wasm 文件?

[英]How to load .wasm file in React-Native?

我一直在尝试加载一个 WebAssembly (.wasm) 文件——生成的 C++ 代码由 Emscripten 编译为 WebAssembly——在 React-Native 应用程序中。

这是我获取 .wasm 文件的代码:

import fs from 'react-native-fs';

if (!global.WebAssembly) {
  global.WebAssembly = require('webassemblyjs');
}

const fetchWasm = async () => {
  const wasm = await fetch(`${fs.MainBundlePath}/calculator.wasm`);

  console.log(wasm);
  // Returns: Response {type: "default", status: 200, ok: true, statusText: undefined, headers: Headers, …}

  const mod = await WebAssembly.instantiateStreaming(wasm);

  console.log(mod);
  // Throws: TypeError: Failed to execute 'compile' on 'WebAssembly': An argument must be provided, which must be a Response or Promise<Response> object
};

我尝试了我能找到的 Google 搜索结果中的所有内容,但到目前为止没有任何效果。 不幸的是,最相关的问题没有得到解答。

有没有人知道我做错了什么? 任何帮助将不胜感激!

我认为仍然 React-native JS 运行时 JSC 仍然不支持 Android 构建中的 WebAssembly 问题仍然存在https://github.com/react-native-community/jsc-android-buildscripts/issues/113

另一种方法是使用 Webview,但我认为这不是您所期望的。 https://github.com/ExodusMovement/react-native-wasm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM