JWebAssembly
JWebAssembly copied to clipboard
Exception in wasm compiler
I tried to do the Hello World example and got the folllowing exception:
....
scan java/util/HashMap.get(Ljava/lang/Object;)Ljava/lang/Object;
type: java/util/HashMap
type: java/util/HashMap$Node
call: java/util/HashMap.getNode(Ljava/lang/Object;)Ljava/util/HashMap$Node;
scan java/lang/StringLatin1.charAt([BI)C
call: java/lang/StringIndexOutOfBoundsException.
WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self. at java.lang.ref.Reference.refersTo0(Reference.java)
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':WASM-Lib:wasm'.
Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self. at java.lang.ref.Reference.refersTo0(Reference.java)
What am I doing wrong? Here is my build.gradle file:
buildscript { repositories { maven { url uri('https://jitpack.io') } } dependencies { classpath 'com.github.i-net-software:jwebassembly-gradle:master-SNAPSHOT' } }
apply plugin: "de.inetsoftware.jwebassembly"
repositories { mavenCentral() maven { url = uri('https://jitpack.io') } }
dependencies { implementation 'com.github.i-net-software:jwebassembly-api:master-SNAPSHOT' }
sourceSets { main { java { srcDir 'src/main/java' } } }
wasm { //Get more debug information if there are problems. //logging.level = LogLevel.DEBUG logging.levelInternal = LogLevel.DEBUG
//Change the output format to the text format *.wat. //This can be helpful to understand the problems if you see the generated code as text format. format = 'text'
//The used JWebAssembly compiler version. The default is the latest release '+'. //You can set any valid Gradle version string or a full dependency string. //The snapshot version is recommended until a stable release. //compilerVersion = 0.4 compilerVersion = 'com.github.i-net-software:jwebassembly:master-SNAPSHOT'
//Write method and parameter names into the output *.wasm file. //The file will be approximate 10% larger. And it generate a source map. //With a source map you can see in the debugger of the browser your source code if available. debugNames = true
//Set an absolute or relative path between the final wasm file location and the source files location. ///This is needed for debugging in the browser. It work only if debugNames = true. //sourceMapBase = '../../src/main/java/' sourceMapBase = '/src/main/java/'
//set the destination dir destinationDir = file( 'targetDir' )
//ignore all referenced native methods without declared replacement in a library and replace them with a stub that throws an exception at runtime //ignoreNative = true }
WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
This is a problem with Java 9 or higher if you referenced a String. A pull request for API project that can fix this is welcome.