0

I recently connected the Spring messaging module to my libgdx project for graceful use of sockets by following this tutorial: https://nexocode.com/blog/posts/spring-dependencies-in-gradle/

Then the task android: mergeDebugJavaResource swears that I have more than one file META-INF/web-fragment.xml

* What went wrong:
Execution failed for task ':android:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'META-INF/web-fragment.xml'. 

Since the problem appears at startup and not build, so I am showing you gradle.build's

build.gradle(app_name)

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.12'
        classpath 'com.google.gms:google-services:4.3.5'
    }
}

plugins {
    id 'java-library'
    id 'org.springframework.boot' version '2.1.0.RELEASE'
}

allprojects {
    apply plugin: "eclipse"

    version = '1.0'
    ext {
        appName = "bogatiry-online"
        gdxVersion = '1.9.14'
        roboVMVersion = '2.3.12'
        box2DLightsVersion = '1.5'
        ashleyVersion = '1.7.3'
        aiVersion = '1.8.2'
        gdxControllersVersion = '2.1.0'
    }

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

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


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

project(":android") {
    apply plugin: "com.android.application"

    configurations { natives }

    dependencies {
        implementation project(":core")
        api "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"
        api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
    }
}

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


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

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

    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        api "com.underwaterapps.overlap2druntime:overlap2d-runtime-libgdx:0.1.0"
        api "com.kotcrab.vis:vis-ui:1.3.0"
    }
}

build.gradle(:core)

plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
}
sourceCompatibility = 1.7
dependencies {
    //Apache
    implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'

    //Json
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'

    //Lombok
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'

    //Spring
    api platform('org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE')
    implementation 'org.springframework.boot:spring-boot-starter-websocket'
    dependencies {
        constraints {
            implementation 'org.springframework.boot:spring-boot-starter-websocket:2.4.5'
        }
    }
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]

eclipse.project.name = appName + "-core"

bootJar {
    enabled = false
}

jar {
    enabled = true
}

build.gradle(:android) (although I think that the problem is not in it, I did not change it when there was no error)

apply plugin: 'com.google.gms.google-services'

android {
    buildToolsVersion "30.0.3"
    compileSdkVersion 30
    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.drownedman.bogatiry"
        minSdkVersion 26
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude("META-INF/*.kotlin_module")
    }
}

// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives {
    doFirst {
        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.copy().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"
                }
            }
        }
    }
}

tasks.whenTaskAdded { packageTask ->
    if (packageTask.name.contains("package")) {
        packageTask.dependsOn 'copyAndroidNatives'
    }
}

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.drownedman.bogatiry/com.drownedman.bogatiry.AndroidLauncher'
}

dependencies {
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:26.8.0')

    // Declare the dependency for the Firebase Authentication library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-database:19.7.0'
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
}

eclipse.project.name = appName + "-android"

I've tried

  1. File -> Invalidate Caches/Restart.
  2. Checked the compatibility of the versions, everything seems to be ok.
  3. Excluded some "META-INF /" files commonly found in errors like this (More than one file was found with OS independent path 'META-INF/LICENSE'). I can exclude this file the same way, but then I get a similar error with another file, then with another one, and so on.

but it doesn't help

Dannik
  • 11
  • 2

1 Answers1

1

Answering my own question, I just excluded this long list of files, as advised in a similar question More than one file was found with OS independent path 'META-INF/LICENSE'

exclude 'META-INF/web-fragment.xml'
exclude 'META-INF/LICENSE.md'
exclude 'META-INF/NOTICE.md'
exclude 'META-INF/spring.schemas'
exclude 'META-INF/spring.tooling'
exclude 'META-INF/spring.handlers'
exclude 'META-INF/spring-configuration-metadata.json'
exclude 'META-INF/spring.factories'
exclude 'META-INF/additional-spring-configuration-metadata.json'
Dannik
  • 11
  • 2