Libgdx: More than one file was found with OS indep

2019-08-18 21:15发布

问题:

Hello fellow Programmers,

I’m having trouble building my libgdx Game for Android with freetype font dependencies.

Libgdx version: 1.9.8

Gradle version: 3.2.0

Android Studio version: 3.1.4

Even without any dependencies for freetype font declared in the root build.gradle file and cleaning of the project I get the following Error when trying to build for Android:

Execution failed for task ':android:transformResourcesWithMergeJavaResForDebug'.

More than one file was found with OS independent path 'libgdx-freetype.dylib'

Following the description for integrating freetype font I added the following dependencies, but I still get the Error above.

project(":desktop") {
    …
    dependencies {
        …
        //freetype font
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
        …
    dependencies {
        …
        //freetype font
        api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
    }
}

project(":core") {
        …
    dependencies {
        …
        //freetype font
        implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    }
}

I’ve tried every possible combination of compile/implementation/api but nothing seems to work.

After some searching in similar Posts I added the following lines to the build.gradle file in the Android Project:

android {
    …
    packagingOptions {
        …
        pickFirst 'libgdx-freetype.dylib'
        pickFirst 'libgdx-freetype64.dylib'
        pickFirst 'gdx-freetype.dll'
        pickFirst 'gdx-freetype64.dll'
    }
    …
}

And now I get the following Error when trying to build for Android:

Execution failed for task ':android:transformDexArchiveWithExternalLibsDexMergerForDebug'.

Program type already present: com.badlogic.gdx.graphics.g2d.freetype.FreeType$Face

Any help resolving this issue would be much appreciated.

EDIT: Created a new Project, copied my code and now it's working...

回答1:

I had the same error as you.

In my gradle.build file I had this added under my core dependencies :

implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion" 

I added this to make a texture packer for my game, and I suppose some of the libraries are creating the error when running the program.

just comment it out (I'm using implementation instead of compile because it's depreciated)

//implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion"