[英]Kotlin compatibility with JavaFXPorts
I would like to build a JavaFX Android app with JavaFXPorts and Kotlin code.我想用JavaFXPorts和 Kotlin 代码构建一个 JavaFX Android 应用程序。 Is it possible to use Kotlin in a JavaFXPorts project?
是否可以在 JavaFXPorts 项目中使用 Kotlin? Here's my example Gradle (version 5.6.4) project:
这是我的示例 Gradle(版本 5.6.4)项目:
Note: Problem with this code is the Kotlin Runtime... Is there any way to bundle everything in the executable Jar and Apk?
注意:此代码的问题在于 Kotlin 运行时...有没有办法将所有内容捆绑在可执行 Jar 和 Apk 中?
.
├── app
│ ├── src
│ │ ├── android
│ │ │ └── AndroidManifest.xml
│ │ └── main
│ │ └── kotlin
│ │ └── com.example
│ │ └── App.kt
│ └── build.gradle.kts
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── build.gradle.kts
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
./settings.gradle.kts ./settings.gradle.kts
pluginManagement {
repositories {
gradlePluginPortal()
jcenter()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.javafxports.jfxmobile") {
useModule("org.javafxports:jfxmobile-plugin:${requested.version}")
}
}
}
}
rootProject.name = "app"
include(":app")
./build.gradle.kts ./build.gradle.kts
plugins {
kotlin("jvm") version "1.3.61" apply false
id("org.javafxports.jfxmobile") version "1.3.18" apply false
}
allprojects {
repositories {
jcenter()
}
}
./app/build.gradle.kts ./app/build.gradle.kts
plugins {
kotlin("jvm")
id("org.javafxports.jfxmobile")
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
application {
mainClassName = "com.example.App"
}
jfxmobile {
android {
manifest = "src/android/AndroidManifest.xml"
applicationPackage = application.mainClassName
buildToolsVersion = "29.0.2"
compileSdkVersion = "28"
targetSdkVersion = "28"
minSdkVersion = "19"
}
}
./app/src/android/AndroidManifest.xml ./app/src/android/AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0">
<supports-screens android:xlargeScreens="true"/>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" android:maxSdkVersion="28"/>
<application android:label="App" android:name="android.support.multidex.MultiDexApplication">
<activity android:label="App" android:name="javafxports.android.FXActivity" android:configChanges="orientation|screenSize">
<meta-data android:name="main.class" android:value="com.example.App"/>
<meta-data android:name="debug.port" android:value="0"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
./app/src/main/kotlin/com/example/App.kt ./app/src/main/kotlin/com/example/App.kt
@file:JvmName("App")
package com.example
import javafx.application.Application
import javafx.geometry.Rectangle2D
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.StackPane
import javafx.stage.Screen
import javafx.stage.Stage
class App : Application() {
override fun start(primaryStage: Stage?) {
val content = Label("Hello")
val root = StackPane(content)
val bounds: Rectangle2D = Screen.getPrimary().visualBounds
val scene = Scene(root, bounds.width, bounds.height)
primaryStage?.scene = scene
primaryStage?.show()
}
}
You can, but you will probably experience some pain along the way, my suggestion is to go with TornadoFx which is Kotlin UI framework built on top of JavaFx.你可以,但你可能会在此过程中遇到一些痛苦,我的建议是使用 TornadoFx,它是构建在 JavaFx 之上的 Kotlin UI 框架。 And it is really nice
它真的很好
Here is the integration guide这是集成指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.