我正在尝试运行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>
以下是我从下载的示例项目中所做的更改
正在从包含示例项目运行构建,例如:gradlew:Kokos:androidInstall
答案 0 :(得分:1)
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
)和依赖项。
答案 1 :(得分:1)
如果这对其他人有帮助,我发现我的情况出了什么问题。
示例项目自述文件建议您应该能够像使用`gradlew:Kokos:androidInstall-的其他项目一样从根示例项目运行项目,或者至少它没有声明。这是不我如何成功运行项目。
要运行此项目,请仅打开Kokos项目并使用gradlew installDebug
此外,我更新了我的依赖项,Davik SDK位置(如Jose Pereda建议的那样),并更改了gradle中设置核心库标志的方式以替换旧方式:
dexOptions {
...
additionalParameters=[ '--core-library']
...
}