xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
108 stars 16 forks source link

TeaVM run issue #92

Closed 4lfg24 closed 1 year ago

4lfg24 commented 1 year ago
I was running the teaVM run task on my newly generated gdx project with gdx-liftoff version 1.11.0.7 (I didn't touch the files in the project whatsoever, leaving core untouched with a basic application adapter displaying a black screen), but in the browser i get this error in the javascript console: java.lang.RuntimeException: (JavaScript) ReferenceError: jl_NoClassDefFoundError__init_ is not defined (anonymous) @ app.js:473 app.js:21021 Uncaught ReferenceError: jl_NoClassDefFoundError__init_ is not defined at cgxgbt_TeaLauncher_getApplicationListener (app.js:12769:5) at cgxgbt_TeaLauncher_main (app.js:12749:28) at TeaVMThread.runner (app.js:595:15) at TeaVMThread.run (app.js:21037:23) at TeaVMThread.start (app.js:21024:10) at $rt_startThread (app.js:21070:31) at app.js:594:9 at onload ((index):8:96) I think this is related to the following error I get in the project's console which says: ` Compiler problems

################################################################# | ERROR[0] | Class: - | Method: - | Text: There's no main class: 'com.alfredo.games.teavm.TeaVMLauncher'` I didn't notice anything weird other than this, thank you in advance for the help.

xpenatan commented 1 year ago

Hello, are you calling setMainClass method?

TeaVMTool tool = TeaBuilder.config(teaBuildConfiguration);
tool.setMainClass(GearsTestLauncher.class.getName());
4lfg24 commented 1 year ago

@xpenatan I'm using kotlin for my project, not java, here's the TeaVMBuilder object:

import java.io.File import com.github.xpenatan.gdx.backends.teavm.TeaBuildConfiguration import com.github.xpenatan.gdx.backends.teavm.TeaBuilder import com.github.xpenatan.gdx.backends.teavm.plugins.TeaReflectionSupplier import com.github.xpenatan.gdx.backends.web.gen.SkipClass

@SkipClass object TeaVMBuilder { @JvmStatic fun main(arguments: Array) { val teaBuildConfiguration = TeaBuildConfiguration().apply { assetsPath.add(File("../assets")) webappPath = File("build/dist").canonicalPath obfuscate = true } val tool = TeaBuilder.config(teaBuildConfiguration) tool.mainClass = "com.mygame.teavm.TeaVMLauncher" TeaBuilder.build(tool) } } And this is the TeaVMLauncher:

@file:JvmName("TeaVMLauncher")

package com.mygame.teavm

import com.github.xpenatan.gdx.backends.teavm.TeaApplicationConfiguration import com.github.xpenatan.gdx.backends.web.WebApplication

import com.mygame.MyGame

/* Launches the TeaVM/HTML application. /

fun main() { val config = TeaApplicationConfiguration("canvas").apply { width = 800 height = 600 } WebApplication(MyGame(),config) }

Could the error be generated by the @file:JvmName("TeaVMLauncher") perhaps?

4lfg24 commented 1 year ago

Also I tried what you suggested with a java project as well but I'm getting the same exact error, did I miss some setup process?

xpenatan commented 1 year ago

Kinda hard to know what could be wrong. gdx-liftoff teavm version is using b2 release. You can use liftoff snapshot which use the b3 version.

I generated kotlin template using gdx-liftoff snapshot and changed backend version to b4, please compare it with your project: https://github.com/xpenatan/gdx-teavm-kotlin-template

4lfg24 commented 1 year ago

Thank you very much @xpenatan it works with your template, I think that the error in my project was that I didn't have this line: compileKotlin { compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11) } In my root build.gradle file, but to anyone planning to use teavm I suggest using your template.