问题描述
我目前的工作在Android游戏,要实现多人。
所以我想用Kryonet:
I am currently working on an Android game and want to implement multiplayer.So i wanted to use Kryonet:
- 我下载了库( )
- 我的核心模块中创建一个libs文件夹
- 复制kryonet-2.21-all.jar在进入它
-
并将其添加为模块中的build.gradle:
- I downloaded the library (https://github.com/EsotericSoftware/kryonet/releases)
- created a libs folder in my core module
- copied the kryonet-2.21-all.jar into it
and added it as Module in the build.gradle:
dependencies {
compile files('src/libs/kryonet-2.21-all.jar') }
在Android Studio中它似乎工作,我曾访问所有的进口等,但我的设备上运行的应用程序时..它坠毁
In Android Studio it seemed to work, i had access to all imports etc., but when running the app on my device.. it crashed
07-16 00:00:44.419 12176-12196/com.cookedapps.robotredemption.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 3363
Process: com.cookedapps.robotredemption.android, PID: 12176
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/esotericsoftware/kryonet/Server;
at com.cookedapps.robotredemption.server.GameServer.<init>(GameServer.java:20)
at com.cookedapps.robotredemption.states.Play.<init>(Play.java:73)
at com.cookedapps.robotredemption.handlers.GameStateManager.getState(GameStateManager.java:39)
at com.cookedapps.robotredemption.handlers.GameStateManager.pushState(GameStateManager.java:49)
at com.cookedapps.robotredemption.handlers.GameStateManager.<init>(GameStateManager.java:21)
at com.cookedapps.robotredemption.main.Game.create(Game.java:41)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.esotericsoftware.kryonet.Server" on path: DexPathList[[zip file "/data/app/com.cookedapps.robotredemption.android-2/base.apk"],nativeLibraryDirectories=[/data/app/com.cookedapps.robotredemption.android-2/lib/arm, /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 com.cookedapps.robotredemption.server.GameServer.<init>(GameServer.java:20)
at com.cookedapps.robotredemption.states.Play.<init>(Play.java:73)
at com.cookedapps.robotredemption.handlers.GameStateManager.getState(GameStateManager.java:39)
at com.cookedapps.robotredemption.handlers.GameStateManager.pushState(GameStateManager.java:49)
at com.cookedapps.robotredemption.handlers.GameStateManager.<init>(GameStateManager.java:21)
at com.cookedapps.robotredemption.main.Game.create(Game.java:41)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
Suppressed: java.lang.ClassNotFoundException: com.esotericsoftware.kryonet.Server
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)
... 10 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我试过/在cmd中和其他的东西gradlew干净,但没有任何帮助。
请给我一个提示IM自从有了这个几个小时被困。谢谢!
I tried /gradlew clean in cmd and other stuff, but nothing helped.Please give me a hint im stuck since a few hours with this.. Thank you!
推荐答案
我找到了解决办法。我做了一个错误的做法。
如何Kryonet添加到libgdx - Android项目:
I found a solution. I had a wrong approach.How to add Kryonet to a libgdx - Android project:
- 转到根的build.gradle
- 到
项目(:核心)
-依赖
并添加:
- Go to root build.gradle
- Go to
project(":core")
-dependencies
and add:
编译com.esotericsoftware:KRYO:3.0.1
编译(com.esotericsoftware:kryonet:2.22.0-RC1){
排除模块:'KRYO
}
- 同步工程与摇篮文件
重要的一点是添加Kryonet,排除KRYO并分别加入KRYO 就像你能避免此异常:
The important point is to add Kryonet, exclude Kryo and adding Kryo separately. Like that you can avoid this exception:
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define
的我希望我能帮助别人这个!的
这篇关于Android的工作室| Libgdx |添加Kryonet图书馆 - 的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!