konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 260 forks source link

Unable to compile due to `Native method xxxx has no implementation` #905

Closed catfoolyou closed 2 months ago

catfoolyou commented 2 months ago

version 0.9.2

When running generateJavascript I get errors along the lines of Native method jdk.internal.loader.BootLoader.setBootLoaderUnnamedModule0(Ljava/lang/Module;)V has no implementation. This happens with both LWJGL related stuff and regular Java native methods.

> Task :generateJavaScript FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateJavaScript'.
> Errors occurred during TeaVM build

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 13m 57s
3 actionable tasks: 3 executed

The rest of the log is available here

Do I need to rewrite all of those native methods or am I doing something wrong?

konsoletyper commented 2 months ago

In your log I can clearly see following methods:

  1. Native methods from lwjgl. lwjgl does not implement them in Java, instead they are written in (I presume) C or C++. TeaVM only deals with Java.
  2. References to internals of implementation of OpenJDK, like sun.java2d. TeaVM is not based on OpenJDK, so does not provide its implementation for these packages. Looks like TeaVM though takes sun.java2d from JVM you are running build (which is obviously OpenJDK), but still fails on native methods.

What you should do, I don't know, there are plenty of possibilities. You can try to re-write these methods somehow, or you can try to patch original minecraft code (which AFAIK, is officially prohibited by Mojang/MS), or you can write your own implementations of libraries used by minecraft (lwjgl, java2d, etc). However, things with network/sockets would be almost impossible, since from JS one can't work with sockets directly. Perhaps, some relay server could help, but I'm also not sure if it's legal WRT to Mojang tems.

catfoolyou commented 2 months ago

Legal issues aside (this is a hobby project), the most logical step to go about would be use reimplementations of LWJGL and java2d that would work with TeaVM? (these exist.)

konsoletyper commented 2 months ago

Sorry, I can't help you here. It's you to take such decisions.