androidgradleandroid-gradle-pluginkryonet

Unable to compile a project due to duplicate class definitions in Kryonet


Caused by: com.android.dex.DexException: Multiple dex files define Lcom/esotericsoftware/reflectasm/MethodAccess;

The above error is preventing my Android project from building, I'm using Kryonet and including it in my build.gradle as a dependency below.

dependancies{
    implementation group: 'kryonet', name: 'kryonet', version: '2.21'
    implementation group: 'com.esotericsoftware', name: 'kryo', version: '4.0.1'

It seems both Kryo and Kryonet include this class, but I don't know how to go about resolving the issue, I can't simply remove Kryo because then I lose access to the serialization libraries.


Solution

  • If you run gradle app:dependencies you can notice that the dependencies tree is:

    +--- kryonet:kryonet:2.21
    |    +--- com.esotericsoftware.reflectasm:reflectasm:1.07
    |    +--- com.esotericsoftware.minlog:minlog:1.2    
    |    \--- org.objenesis:objenesis:2.1 -> 2.5.1
    +--- com.esotericsoftware:kryo:4.0.1
    |    +--- com.esotericsoftware:reflectasm:1.11.3
    |    |    \--- org.ow2.asm:asm:5.0.4
    |    +--- com.esotericsoftware:minlog:1.3.0
    |    \--- org.objenesis:objenesis:2.5.1
    

    They have exactly the same dependencies, but Kyro depends on newer versions. So I would simply remove the dependency on kyronet

    implementation group: 'kryonet', name: 'kryonet', version: '2.21'
    

    EDIT

    This should solve your problem and let you keep both of the libraries

    implementation (group: 'kryonet', name: 'kryonet', version: '2.21') {
        exclude group: 'com.esotericsoftware.reflectasm', module: 'reflectasm'
        exclude group: 'com.esotericsoftware.minlog', module: 'minlog'
    }
    implementation group: 'com.esotericsoftware', name: 'kryo', version: '4.0.1'