如何解析“在 APK META-INF/* 中复制的重复文件”

我在一个商业机器人应用程序工作。 我还使用了一些以不同许可证类型授权的图书馆,其中一些说明如下:

如果库中有一个带有属性说明的“ NOTICE”文件,则在分发时必须包含该“ NOTICE”

(例如,其中一个是根据 Apache 许可证2.0授权的)。

图书馆不止一个。当我使用 格莱德安卓工作室进行构建时,会得到以下构建错误:

* What went wrong:
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.txt

到目前为止,我在互联网和 stackoverflow 上找到的答案建议,通过添加到 build.gradle文件中以下内容,从打包中删除 Licse.txt (通知. txt 或其他可能会造成这种干扰的文件) :

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

参见例子: Android Studio 0.4复制 APK META-INF/LICENSE.txt 中复制的文件

根据这些库的许可证(例如 Apache 许可证2.0) ,许可证和通知文件应该是 包括

我的问题: 我怎样才能添加多个与许可相关的文件(如 许可证注意,短信等)从我的项目级,以符合许可(技术细节:许可文本将连接) ?

65796 次浏览

There is a solution if you have only one license using the name license.txt (read: all license.txt copies are identical):

packagingOptions {
pickFirst  'META-INF/license.txt'
}

Otherwise, Google also released a Gradle plugin to manage dependencies licenses. See here. I didn't try it, but it looks like it's capable of aggregating every dependency, and even generating an activity displaying all of those licenses.

You can add multiple licence in gradle see this

Add following into respective build.gradle file

packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}

Surely it will work

packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'   }

I faced the same issue with my application. You need to make sure you have not added any libraries twice. If you have followed the firebase documentation https://firebase.google.com/docs/android/setup

Then you should not add firebase library inside android studio i.e. file->project structure->cloud->firebase

You have to do only one of the both, to use firebase in your android application.

At the end clean and rerun your app.

I think you need to include only these options in build.gradle:

android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
}

As an alternative to Marc Plano-Lesay's answer, you can also merge the files:

packagingOptions {
merge "META-INF/license.txt"
}

Reference: Gradle API 4.2 Packaging Options