Reputation: 3145
I'm having a hard time exactly what is causing this error on adb because I am using Kotlin, TornadoFX (a JavaFX Kotlin library) and Gluon with JFXMobile. When I use Gluon's androidInstall
to build my project I encounter this error, along with a black screen:
java.lang.ClassNotFoundException: Didn't find class "com.my.app.example.Main" on path: DexPathList
I'm trying to use JavaFX 3D in this application, but I don't think that it's causing the error.
I checked my Android Manifest, and the package name is the same as my project.
My project hierarchy is like so:
root
libs
src
android
ios
main
kotlin
com.my.app.example
Main.kt
Which might be causing Android to not be able to find the file? Since there's no Java folder.
I have all of the following in my gradle file, compiled successfully:
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'no.tornado:tornadofx:1.7.12'
compile 'no.tornado:tornadofx-android-compat:1.0.1'
compile 'com.gluonhq:charm:4.3.7'
compile fileTree(dir: 'libs', include: '*.jar')
}
The fileTree(dir: 'libs', include: '*.jar')
is for an external library that I am using to import ObjModels for JavaFX, located in the libs
folder of my project.
Things I am suspicious of causing this error:
libs
folder not being included correctly in the Android apk and messing it all up somehowPlease note that this project runs fine on my desktop, so it's not a problem with my source code, just something on the Android-specific end.
Any ideas what is causing this? Thanks for any help!
Upvotes: 1
Views: 985
Reputation: 45456
This is a very simple sample of a Gluon Mobile project working with Kotlin that can be deployed to Android/iOS.
Using the Gluon plugin for IntelliJ, created a project (Single View), and modify the build.gradle file:
build.gradle
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
repositories {
jcenter()
mavenCentral()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluon.kotlin.Main'
dependencies {
compile 'com.gluonhq:charm:4.4.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'no.tornado:tornadofx:1.7.12'
compile 'no.tornado:tornadofx-android-compat:1.0.1'
}
jfxmobile {
downConfig {
version = '3.6.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
Remove the /src/main/java
package, and add the /src/main/kotlin
one.
The Main.kt
class is in /src/main/kotlin/com/gluon/kotlin/Main.kt
:
Main.kt
package com.gluon.kotlin
import com.gluonhq.charm.glisten.application.MobileApplication
import com.gluonhq.charm.glisten.mvc.View
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon
import javafx.geometry.Pos
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import tornadofx.plusAssign
class Main: MobileApplication() {
override fun init() {
addViewFactory(MobileApplication.HOME_VIEW, {
val view = View("home")
val vBox = VBox()
with (vBox) {
alignment = Pos.CENTER
spacing = 30.0
this += Button("Kotlin", MaterialDesignIcon.CODE.graphic()).apply {
println("Click")
}
this += Label("Gluon Mobile - Kotlin")
}
with(view) {
this.center = vBox
this.setOnShown {
with(MobileApplication.getInstance().appBar) {
this.navIcon = MaterialDesignIcon.MENU.button().apply {
println("Click")
}
this.titleText = "Gluon Mobile - Kotlin"
}
}
}
view
})
}
}
You can run the project on desktop, and without modifying the AndroidManifest file, deploy to an Android device using the androidInstall
task.
Upvotes: 0