techfly
techfly

Reputation: 1866

Android Build Error: DuplicateFileException

In my newly created Android project, I make use of the Jackson JSON/XML parser library. The problem is, when trying to build. I get this exception:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE

The problem is that the library consists of three JARs, each containing its own license file, and each of them named "LICENSE", hence the error. See the image:

three jars

Now I have researched how to fix it and there are quite a lot of StackOverflow questions regarding this exact problem, yet all of them only give the solution to exclude the LICENSE files from packaging: packagingOptions { exclude 'META-INF/LICENSE' } (or alternatively, use "pickFirst" instead of "exclude")

My problem with this solution is that I think that in the shipping APK, the licenses must not be missing or else I could get legal problems. Is there any other solution (like force-rename to LICENSE-1 or whatever)?

Upvotes: 0

Views: 52

Answers (1)

DeKaNszn
DeKaNszn

Reputation: 2730

Change your app build.gradle:

android {
    ...
    packagingOptions {
        exclude 'META-INF/LICENSE' // add this
    }
}

Put unique licenses to assets and create view for show all licenses

Upvotes: 1

Related Questions