Trying to get Kryonet to work with Android

1.6k views Asked by At

Ok I have googled the hell out of this issue, but I can not for the life of me fix my issue.

First off I am using eclipse making a game within the libGDX framework. I have imported kryonet within my projects.

It works when I compile for the PC.

My issue is when I compile for the Android, it gives me this error:

Dx trouble writing output: already prepared
[Dex Loader] Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/jsonbeans/Json$FieldMetadata;
[-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/jsonbeans/Json$FieldMetadata; 

I have done everything I can, I have added the libraries to my build list in my android project, I have added them to the /lib folder for the android project. I deleted my DEX folder. I cleaned my build and restarted. my /gen is above my /src in my order and export I am clearly missing something basic. I have spent all today googling this.

List of library .JARs i am using relating to Kryonet:

asm 
jsonbeans 
junit 
kryo 
kryo-debug
minlog 
minlog-none 
objenesis 
reflectasm

Can someone please help me out? Thank you :)

-edit- if I remove jsonbean I get

[2013-12-19 22:35:43 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/kryo/ClassResolver;
[2013-12-19 22:35:43] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/kryo/ClassResolver;
2

There are 2 answers

2
Krtko On BEST ANSWER

Oh wow Ok I am stoked. Thank you Kumar Bibek for helping me. I am answering my own question here in case anyone else was as much of a noob as I am and equally as bad luck with google as I did :)

Ok first install Kryonet's source to your main GDX project /src folder (the platform independent project).

Next copy the required .JARs into the /lib of your main GDX project.

Then in Eclipse right click on your main project and add the libraries to your build path. Make sure to check them under the Order and export (this might not be necessary)

(this is where I made a mistake) Make sure that you don't put the required .JARs into your android source folder's /lib only in the main GDX project /lib folder

Then in Eclipse right click on your android GDX project and click Add JARs. In this menu go into your main GDX project's /lib folder and add all the necessary JARs for Kryonet. Then go into Order and Export and check all these JARs.

Now you can compile your Android GDX project Thanks again stack overflow I love you. I hope that made sense and helps other noobs, as I am pretty tipsy now lol :)

2
Kumar Bibek On
Dx trouble writing output: already prepared
[Dex Loader] Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/jsonbeans/Json$FieldMetadata;
[-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/esotericsoftware/jsonbeans/Json$FieldMetadata; 

As it says, there's duplicate references of the same package. You will need to figure out where exactly these packages are in the libraries that you are adding. And figure out a way to keep only one copy of it.

I am guessing kyronet already has the jsonbeans included. May be try removing the jsonbeans library from your list of dependencies.