Java, Android Studio, Gradle, LibGDX, KryoNet - Error: Program type already present: com.esotericsoftware.jsonbeans.Json$Serializer

232 views Asked by At

This problem popped up out of nowhere on me and it only affects the Android project and building an APK.

I'm not entirely sure what the problem is. I spent the better part of last night on Google trying to find something, anything, out. I got nowhere with it, so here I am.

Here is the project's overall gradle.build file:

buildscript {


    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = ""
    ext {
        appName = "fade-online"
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.1'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        google()
        jcenter()
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"

    }
}

project(":rtoserver") {
    apply plugin: "java"

    dependencies {
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}

project(":editorsuite") {
    apply plugin: "java"

    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    android {
        dexOptions {
            preDexLibraries = false
        }
    }

    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"

    }
}

project(":ios") {
    apply plugin: "java"
    apply plugin: "robovm"


    dependencies {
        implementation project(":core")
        implementation "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        implementation "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        implementation "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"

    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

Here is my gradle.build file for the Android project:

    android {
    buildToolsVersion '28.0.3'
    compileSdkVersion 28
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }
    packagingOptions {
        exclude 'META-INF/robovm/ios/robovm.xml'
    }
    defaultConfig {
        applicationId "com.forgottenartsstudios.fadeonline"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 7
        versionName '0.7.000'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

task copyAndroidNatives() {
    file("libs/armeabi/").mkdirs()
    file("libs/armeabi-v7a/").mkdirs()
    file("libs/arm64-v8a/").mkdirs()
    file("libs/x86_64/").mkdirs()
    file("libs/x86/").mkdirs()

    configurations.natives.files.each { jar ->
        def outputDir = null
        if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
        if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if (jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if (outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}
task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.forgottenartsstudios.fadeonline/com.forgottenartsstudios.fadeonline.AndroidLauncher'
}
eclipse {

    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    classpath {
        plusConfigurations += [project.configurations.compile]
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear()
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}
idea {
    module {
        sourceDirs += file("src")
        scopes = [COMPILE: [plus: [project.configurations.compile]]]

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance()
                builder.current = node
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value: "true")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
    implementation files('libs/kryonet-2.21-all.jar')
}

Here's the Core gradle.build file:

apply plugin: "java"
sourceCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = ["src/"]
eclipse.project {
    name = appName + "-core"
}
dependencies {
    implementation files('libs/kryonet-2.21-all.jar')
    implementation project(':rtoserver')
}

Here's the Server gradle.build file:

apply plugin: 'java'

dependencies {
    implementation files('libs/kryonet-2.21-all.jar')
    implementation 'com.badlogicgames.gdx:gdx:1.9.8'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

And here's the Desktop gradle.build file:

apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src/"]
project.ext.mainClassName = "com.forgottenartsstudios.fadeonline.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets")
task run(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}
task dist(type: Jar) {
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    from { configurations.compile.collect { zipTree(it) } }
    from files(project.assetsDir)

    baseName = "FADEOnline"

    manifest {
        attributes 'Main-Class': project.mainClassName
    }
}
dist.dependsOn classes
eclipse {
    project {
        name = appName + "-desktop"
        linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC'
    }
}
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
    doLast {
        def classpath = new XmlParser().parse(file(".classpath"))
        new Node(classpath, "classpathentry", [kind: 'src', path: 'assets'])
        def writer = new FileWriter(file(".classpath"))
        def printer = new XmlNodePrinter(new PrintWriter(writer))
        printer.setPreserveWhitespace(true)
        printer.print(classpath)
    }
}

dependencies {
    implementation project(path: ':android', configuration: 'default')
}

I'm fairly new to StackOverflow, so I apologize for anything I do wrong.

If you need more information, please let me know and I will provide it as soon as possible.

Thank you.

0

There are 0 answers