libgdx / gdx-liftoff

A modern setup tool for libGDX Gradle projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TeaVM fix 1.0.0-b3

Quillraven opened this issue · comments

commented

Hey boys and girls,

there was a bug in TeaVM 1.0.0-b2 which is currently used by gdx-liftoff which threw an exception during compilation stage:
xpenatan/gdx-teavm#65

The guys over there released a new version 1.0.0-b3 which fixed the issue (at least for me) but this version also requires some other changes because they remove the "web" package and classes.

The things I had to do:

  • change version from 1.0.0-b2 to 1.0.0-b3
  • in root gradle file I made sure that the mentioned repositories are part of it:
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    maven { url "https://teavm.org/maven/repository/" }
    
  • change sourceCompatibility in root and lwgjl3 gradle from 1.8 to 11 (Not sure if this is something critical or not. I read that LibGDX nowadays also requires Java11 for compilation so it might be just fine?)
  • remove following line from teavm gradle dependencies:
    implementation "com.github.xpenatan.gdx-teavm:backend-web:$gdxTeaVMVersion"
    
  • in TeaVMBuilder.kt I had do fix the import for SkipClass to import com.github.xpenatan.gdx.backends.teavm.gen.SkipClass
  • in TeaVMLauncher.kt I had to replace WebApplication with TeaApplication

After those changes, my compilation worked again and I was able to run it successfully in the browser again. The project worked at the beginning with a basic LibGDX setup and ECS Fleks but at some point it broke. Unfortunately, I cannot tell when exactly it happened but it was after adding box2d and box2dlights but not sure if it was related to that.

Anyway, in case you need a reference for the adjusted files, have a look at: Quillraven/MysticGarden@b3f2301

@czyzby: can you please also verify that with your example teavm projects?

commented

Sample projects are generated with gdx-liftoff via a GitHub Action, so once these issues are addressed here, I can trigger the actions manually and verify whether they compile correctly.

I believe I fixed these in 9604750 yesterday, but today Xpe mentioned wanting to make a 1.0.0-b4 bugfix release, so there may still be bugs in 1.0.0-b3. There's also the thing where TeaVM requires JDK 11 now, and I've moved the default Java version to 11 so Android and TeaVM can work out-of-the-box. The Java version can still be changed as low as 7 in the Advanced tab. If there are other options here that don't involve requiring a JDK 11 or higher, that would be great, but Android is kind-of forcing our hand.

EDIT: I didn't add the Maven repository maven { url "https://teavm.org/maven/repository/" }, but it still seems to work. As for libGDX, it needs Java 8 last I checked to build most things, but probably needs 11 for Android. Building the whole libGDX repo probably does, then, need 11.

commented

Thank you tommy for your great work with this setup tool 👍

commented

I think you still need to update some imports in the template @tommyettinger. These are the errors I'm getting when generating a sample automatically with Kotlin template:

> Task :teavm:compileKotlin FAILED
5 actionable tasks: 5 executed
e: file:///home/runner/work/ktx-sample-web-project/ktx-sample-web-project/teavm/src/main/kotlin/ktx/demo/teavm/TeaVMBuilder.kt:10:2 Unresolved reference: SkipClass
e: file:///home/runner/work/ktx-sample-web-project/ktx-sample-web-project/teavm/src/main/kotlin/ktx/demo/teavm/TeaVMLauncher.kt:6:41 Unresolved reference: web
e: file:///home/runner/work/ktx-sample-web-project/ktx-sample-web-project/teavm/src/main/kotlin/ktx/demo/teavm/TeaVMLauncher.kt:15:5 Unresolved reference: WebApplication

Additionally, the following warning is raised:

'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
By default will become an error since Gradle 8.0+! Read more: https://kotl.in/gradle/jvm/target-validation
commented

I can help with the warning. I fixed that yesterday in my project.

In the root Gradle file I had to adjust this block:

configure(subprojects - project(':android')) {
  apply plugin: 'java-library'
  apply plugin: 'kotlin'
  sourceCompatibility = 11
  compileJava {
    options.incremental = true
  }
  compileKotlin {
    compilerOptions.jvmTarget = JvmTarget.JVM_11
  }
}

I added the compileKotlin block and then the warning was gone.

OK, I've fixed the Kotlin template errors and added the compileKotlin block. I'll commit this in a few hours (I must continue the commit streak!). For the first, I had already made the changes to the Java template, so these were quick to add to Kotlin's template, too. For the second, my approach isn't especially elegant; I just check that both the Kotlin plugin and the TeaVM platform are in use, and if so I emit the compileKotlin block. To avoid having to import JvmTarget (which seems to be in the Kotlin DSL's package, for some reason, and isn't immediately available to Groovy), I'm using a fully-qualified name, which at least limits the changes to this block.

commented

I can confirm the app was exported correctly after the changed, thanks.