如何用Kotlin和Tornado FX设置Gluon应用程序

我目前尝试将以下技术结合起来:

  • 胶子(手机)
  • Gradle(依赖于Gluon,因为他们依赖它)
  • Kotlin(因为这是一个很好的语言,我想深入)
  • 龙卷风FX(我想这是JavaFX,Anko是Android的)

问题是,我对Intellij-IDEA相对比较陌生,并且在正确设置它的时候遇到了问题,尽管我认为build.gradle文件是足够合适的。

这是我的build.gradle看起来如此之远:

 buildscript { ext.kotlin_version = '1.0.6' repositories { jcenter() mavenCentral() } dependencies { classpath 'org.javafxports:jfxmobile-plugin:1.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: 'org.javafxports.jfxmobile' apply plugin: 'kotlin' // apply plugin: 'com.android.application' // apply plugin: 'kotlin-android' repositories { jcenter() mavenCentral() maven { url 'http://nexus.gluonhq.com/nexus/content/repositories/releases' } } mainClassName = 'eu.dzim.test.Main' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile 'com.gluonhq:charm:4.2.0' compile 'no.tornado:tornadofx:1.5.9' compile 'no.tornado:tornadofx-controls:1.0.4' } jfxmobile { downConfig { version = '3.1.0' // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead plugins 'display', 'lifecycle', 'statusbar', 'storage' } android { manifest = 'src/android/AndroidManifest.xml' } } 

我最初设法阻止IDE投诉Kotlin。 我将一个简单的应用程序类转换成如下所示:

 package eu.dzim.test import com.gluonhq.charm.down.Platform import javafx.application.Application import javafx.scene.Scene import javafx.scene.layout.BorderPane import javafx.stage.Screen import javafx.stage.Stage /** * Created by daniel on 06.01.17. */ class Main : Application() { @Throws(Exception::class) override fun start(stage: Stage) { var width = -1.0 var height = -1.0 if (Platform.isDesktop()) { width = 480.0 height = 640.0 stage.title = "Test" } val primaryScreen = Screen.getPrimary() val visualBounds = primaryScreen.visualBounds if (width < 0 || height < 0) { width = visualBounds.width height = visualBounds.height } val root = BorderPane() val scene = Scene(root, width, height) stage.scene = scene stage.show() } } 

但是现在我被困住了,因为对Tornado FX的依赖没有得到很好的解决。 我想创建一个View并开始

 package eu.dzim.test import tornadofx.View import tornadofx.borderpane class Root : View("My View") { override val root = borderpane { } } 

但像import tornadofx.View这样的import tornadofx.View永远不会得到解决。

有没有问题,因为龙卷风似乎使用Kotlin 1.0.5 ,而我想使用1.0.6 ? (虽然这没有效果,如果我改变它,关于(仍未使用,因为“未解决”) View …)

问候,丹尼尔

当IDEA分析构建文件并生成无效的元数据时,它看起来有些问题,可能是由于对构建配置的增量更改。 要重新生成元数据,请执行以下操作

  • 关闭IDEA
  • 删除项目文件夹中的.idea文件夹
  • 导入项目

这次元数据将从已经完成的构建文件生成,并且应该被正确设置。

另外请注意,Kotlin插件默认会在src/main/kotlin编译Kotlin源src/main/kotlin 。 或者更改源文件夹或者Kotfigure Kotlin插件来编译src/main/java源代码:

 sourceSets { main.kotlin.srcDirs += 'src/main/java' }