kotlin-graphics/imgui

Can't import uno.glfw.GlfwWindow

zeroeightysix opened this issue · 12 comments

Looks like I'm experiencing the same issue as #101, but am using gradle to pull imgui dependencies in.
IntelliJ, or gradle while building - can resolve references to most imgui classes (e.g. import imgui.ImGui; works fine). However, uno.glfw.GlfwWindow just doesn't seem to exist, even though IntelliJ lists it in the dependencies just fine, and can even view its (decompiled) source code.

The build.gradle I'm using to reproduce this problem looks like this:

plugins {
   id 'java'
}

repositories {
   mavenCentral()
   maven { url 'https://jitpack.io' }
}

dependencies {
   compile 'com.github.kotlin-graphics:imgui:-SNAPSHOT'
}

The problem also persists with the more complete build.gradle listed on the wiki or in the README.

In an editor references to GlfwWindow cannot be resolved, but ImGui can:
image

Running gradle's build task, it insists uno.glfw does not exist:
image

In the 'External Libraries' listing, the class is listed (and can be viewed without error):
image

These results are produced using java version:

openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10)
OpenJDK 64-Bit Server VM (build 11.0.5+10, mixed mode)

If I switch to OpenJDK 8, gradle will fail even before an error for GlfwWindow, producing the following error:

/home/ridan/IdeaProjects/imguitest/src/main/java/Main.java:1: error: cannot access ImGui
import imgui.ImGui;
            ^
  bad class file: /home/ridan/.gradle/caches/modules-2/files-2.1/com.github.kotlin-graphics.imgui/imgui-core/-SNAPSHOT/55853bf32a87b9129ac7c136ca312354dc2083e2/imgui-core--SNAPSHOT.jar(imgui/ImGui.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

However, If I use the jdk8 branch(es) made by @AlexApps99, the issue persists like it did with JDK 11.

Edit: any references to the uno package don't work.

If you need any more information, just ask. Thanks!

Looks like adding uno-sdk and glm explicitly fixes the issue:

    compile "com.github.kotlin-graphics:imgui:-SNAPSHOT"
    compile 'com.github.kotlin-graphics:uno-sdk:f528113bf45e43406953d6881915467d85a20881'
    compile 'com.github.kotlin-graphics.glm:glm:1b4ac18dd1a3c23440d3f33596688aac60bc0141'

but that's not a very elegant or maintainable solution.

I guess this has to do with the gradle implementation keyword..

I use that explicitely to avoid any leaking of imgui dependencies into the application using imgui (corresponding issue)

but based on what you make here notice, it looks like indeed uno shall be switched to api

I dont understand why you need also glm though..

Do you want to do a quick test with another branch and api uno?

Of course. Please tell me what to do.

I dont understand why you need also glm though..

It's the same problem.
imgui.button(String string, Vec2 vec) accepts a Vec2 - which I have to explicitly add (entire glm library) in order to be able to use it.

The same goes for the kotlin stdlib.
imgui.showDemoWindow can accept either a boolean[] or a KMutableProperty.
Even if I use the constructor that accepts a boolean[], gradle complains:

(showDemoWindow is of type boolean[])

/home/ridan/IdeaProjects/kami/src/main/java/me/zeroeightsix/kami/gui/KamiGuiScreen.java:52: error: cannot access KMutableProperty0
            imgui.showDemoWindow(showDemoWindow);
                 ^
  class file for kotlin.reflect.KMutableProperty0 not found

adding stdlib fixes it again:

    compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.61'
  • create a new branch
  • change implementation to api in uno-gl (here)
  • commit and copy the corresponding revision number (in Idea git Log view, right click on the commit, "Copy ..")
  • comment the explicit compile (which is deprecated btw, use implementation)
  • request the very same commit in your program instead of -SNAPSHOT

Also: you dont need all the backends, imports only what you really need, which is (I think) the gl backend

["core", "gl"].each {
        implementation "${kx}.uno-sdk:uno-$it:$uno_version"
    }

Ps: yep, true, glm is needed as well (and kotlin reflect, which is weird though)

I tried with this commit: 8f91012
Unfortunately, the same problem persists.

  • be sure you have listed in your dependencies the right imgui corresponding to the commit version requested
  • try also the same in the core module

And also be sure you are importing only those two modules (gl and core)

Using this:

ext {
    imguiVersion = "2f61b9e67433573841857a5ab3f763e69ac594a7"
}
["gl", "core"].each {
    implementation("com.github.kotlin-graphics.imgui:imgui-$it:$imguiVersion")
}

(commit 2f61b9e)

The problem persists. Am I doing something wrong?

Apparently no.

I might have a similar playground where I could test this, but it still require a lot of re-work before reaching a buildable status (it's the vulkan sample port of sascha), which means not in the short term future

You may want to open an issue on StackOverflow targetting explicitely gradle

Okay, will do. Thanks for the help (and the amazing libraries)!

exuvo commented

I just realised this is actually the same problem i had in #143 . If you would have opened intellij module settings -> dependencies in the right part you would have seen that uno-sdk is listed only as scope runtime but should be compile. Should be fixed with next release when dependencies for uno-core and glm are changed to api from implementation (as that resolves it in my local branch).

this should be solved