libgdx / gdx-liftoff

A modern setup tool for libGDX Gradle projects
Apache License 2.0
525 stars 48 forks source link

TeaVM fix 1.0.0-b3 #120

Closed Quillraven closed 1 year ago

Quillraven commented 1 year ago

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: https://github.com/xpenatan/gdx-teavm/issues/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:

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: https://github.com/Quillraven/MysticGarden/commit/b3f2301557723e323bba17537c8b8abbd40919f6

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

czyzby commented 1 year ago

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.

tommyettinger commented 1 year ago

I believe I fixed these in https://github.com/tommyettinger/gdx-liftoff/commit/9604750bcfff9a4f7a1bc4fcbcdcaa244058260d 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.

Quillraven commented 1 year ago

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

czyzby commented 1 year ago

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
Quillraven commented 1 year ago

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.

tommyettinger commented 1 year ago

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.

czyzby commented 1 year ago

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