我正在尝试运行javafxports示例项目Kokos,因为我想在Android Studio内置的应用程序中使用JavaFX组件,但无法正确构建它,我可以构建所有其他示例但这种混合方法不起作用.
当我构建我只是得到一个黑屏和错误“java.lang.ClassNotFoundException:没有找到类”org.javafxports.kokos.Main“在路径上:DexPathList [[zip file”/data/app/org.javafxports .kokos-2 / base.apk “]”
据我所知,没有任何kokos类实际上内置到apk中,因此它无法找到它们,但我无法弄清楚为什么,这是我能找到的这种方法的唯一样本.
是否有人能够成功构建和运行Kokos样本,如果是,是否需要进行任何修改?
或者,是否有另一个在这样的Android项目中使用JavaFX组件的例子,我可以将其用作基础?我只是希望能够拥有一个由原生Android活动组成的应用程序,但能够启动JavaFX活动.
给出的错误消息是:
02-01 21:43:16.406 17575-17575/org.javafxports.kokos V/DalvikLauncher: Launch JavaFX application on DALVIK vm.
02-01 21:43:16.409 17575-17575/org.javafxports.kokos V/DalvikLauncher: We have JavaFX on our current (base) classpath, registered exit listener
02-01 21:43:16.410 17575-17575/org.javafxports.kokos E/DalvikLauncher: Launch failed with exception.
java.lang.ClassNotFoundException: Didn't find class "org.javafxports.kokos.Main" on path: DexPathList[[zip file "/data/app/org.javafxports.kokos-1/base.apk"],nativeLibraryDirectories=[/data/app/org.javafxports.kokos-1/lib/arm, /data/app/org.javafxports.kokos-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at javafxports.android.DalvikLauncher.resolveApplicationClass(DalvikLauncher.java:262)
at javafxports.android.DalvikLauncher.launchApp(DalvikLauncher.java:164)
at javafxports.android.FXDalvikEntity.getLauncherAndLaunchApplication(FXDalvikEntity.java:162)
at javafxports.android.FXDalvikEntity.surfaceCreated(FXDalvikEntity.java:304)
at android.view.SurfaceView.updateWindow(SurfaceView.java:583)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2063)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1115)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6023)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.javafxports.kokos.Main" on path: DexPathList[[dex file "/data/dalvik-cache/xposed_XResourcesSuperClass.dex"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 23 more
Suppressed: java.lang.ClassNotFoundException: org.javafxports.kokos.Main
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 24 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
02-01 21:43:16.411 17575-17575/org.javafxports.kokos V/FXEntity: Called Surface changed [1080, 1848], format 4
02-01 21:43:16.411 17575-17575/org.javafxports.kokos V/FXActivity native: [JVDBG] SURFACE created native android window at 0xa47cd508, surface = 0xff9d0f60
02-01 21:43:16.412 17575-17575/org.javafxports.kokos V/FXEntity: Called Surface redraw needed
02-01 21:43:16.423 17575-17575/org.javafxports.kokos V/FXEntity: Called Surface redraw needed
02-01 21:43:16.441 1378-1536/system_process I/ActivityManager: Displayed org.javafxports.kokos/javafxports.android.FXActivity: +330ms
这是我的app / build.gradle文件,我试图更新依赖项但仍有问题,有什么明显的错误吗?
我原来的app / build.gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.5.0'
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
repositories {
jcenter()
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
// minSdkVersion 16
buildToolsVersion "23.0.2"
dexOptions {
preDexLibraries = false
}
defaultConfig {
applicationId "lodgon.org.kokos"
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
multiDexEnabled true
}
sourceSets {
main {
jniLibs.srcDir file("/opt/dalvik-sdk/rt/lib")
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile fileTree(include: ['*.jar'], dir: '/opt/dalvik-sdk/rt/lib/ext')
}
project.tasks.withType(com.android.build.gradle.tasks.Dex) {
additionalParameters=['--core-library']
}
我编辑的app / build.gradle
我应用了一些建议的修复程序,并更改了applicationID和dalvik-sdk位置,但我仍然遇到同样的问题,文件现在看起来像这样:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.5.0'
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
repositories {
jcenter()
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
// minSdkVersion 16
buildToolsVersion "23.0.2"
dexOptions {
preDexLibraries = false
}
defaultConfig {
applicationId "javafxports.org.kokos"
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
multiDexEnabled true
}
sourceSets {
main {
jniLibs.srcDir file("C:\\Users\\AdamL\\.gradle\\caches\\modules-2\\files-2.1\\org.javafxports\\dalvik-sdk\\8.60.8\\6630ec66e4703c910ac3fd6151a8494c8b59186b\\unpacked\\dalvik-sdk\\rt\\lib")
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile fileTree(include: ['*.jar'], dir: 'C:\\Users\\AdamL\\.gradle\\caches\\modules-2\\files-2.1\\org.javafxports\\dalvik-sdk\\8.60.8\\6630ec66e4703c910ac3fd6151a8494c8b59186b\\unpacked\\dalvik-sdk\\rt\\lib\\ext')
}
project.tasks.withType(com.android.build.gradle.tasks.Dex) {
additionalParameters=['--core-library']
}
Android清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="javafxports.org.kokos" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="javafxports.org.kokos.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这些是我从下载的示例项目中所做的更改
> JavaFXPorts插件已更改为版本1.32
>将android-gradle插件引用更改为2.2.3版
>将retrolamba版本更改为3.5.0
>更改了applicationID以更正一个
>更改了dalvik-sdk位置以更正其中一个
构建正在从包含示例项目运行,如:gradlew:Kokos:androidInstall
解决方法:
build.gradle文件有几个问题.
应用程序ID错误,您应该使用包名:
defaultConfig {
applicationId "javafxports.org.kokos"
...
}
dalvik-sdk路径不正确.你拥有的那个(/ opt / dalvik-sdk)是基于Linux的.
如果您已经尝试过其他JavaFXPorts samples,那么您已经下载了最新版本的dalvik-sdk,它将安装在.gradle存储库中.
你会发现它:
C:\Users\<user>\.gradle\caches\modules-2\files-2.1\org.javafxports\dalvik-sdk\8.60.8\<id>\unpacked\dalvik-sdk
找到正确的路径并在sourceSets(jniLibs.srcDir)和依赖项中替换它.