Java 如何解决“在 APK META-INF/* 中复制的重复文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33923461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I resolve "Duplicate files copied in APK META-INF/*"
提问by Flowryn
I am working at a commercial android application. I am also using some libraries licensed under different license types some of them stating the following:
我在一个商业 android 应用程序工作。我还使用了一些在不同许可证类型下获得许可的库,其中一些声明如下:
If the library has a "NOTICE" file with attribution notes, you must include that NOTICE when you distribute
如果图书馆有一个带有署名注释的“NOTICE”文件,您必须在分发时包含该 NOTICE
(One of them is licensed under Apache License 2.0for example).
(例如,其中之一在Apache License 2.0下获得许可)。
There is more than one library. When I do the build with gradleor with Android StudioI obtain the following build error:
有不止一个图书馆。当我使用gradle或Android Studio进行构建时,出现以下构建错误:
* 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
The answers that I found until now on the internet and stackoverflow suggest to remove the license.txt(notice.txt or other files that could interfere like this) from packaging by adding to build.gradle
file the following:
到目前为止,我在 Internet 和 stackoverflow 上找到的答案建议通过将build.gradle
以下内容添加到文件中来从包装中删除 license.txt(notice.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'
}
See for example: Android Studio 0.4 Duplicate files copied in APK META-INF/LICENSE.txt
参见示例:Android Studio 0.4 Duplicate files Copy in APK META-INF/LICENSE.txt
According to the license of those libraries(Apache License 2.0for instance), the license and notice files should be included.
根据这些库的许可(例如Apache License 2.0),应包含许可和通知文件。
My question:How can I add multiple files related to licensing(such as license.txt, notice.txtetc) from gradle into my project in order to be compliant with the licenses(technical detail:licences texts will be concatenated)?
我的问题:如何将与许可相关的多个文件(例如license.txt、notice.txt等)从 gradle 添加到我的项目中以符合许可证(技术细节:许可证文本将被连接)?
采纳答案by Marc Plano-Lesay
There is a solution if you have only one license using the name license.txt
(read: all license.txt
copies are identical):
如果您只有一个使用该名称的许可证,则有一个解决方案license.txt
(阅读:所有license.txt
副本都相同):
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.
另外,Google 还发布了一个 Gradle 插件来管理依赖项许可证。见这里。我没有尝试过,但看起来它能够聚合每个依赖项,甚至生成一个显示所有这些许可证的活动。
回答by Max Droid
Add following into respective build.gradle file
将以下内容添加到相应的 build.gradle 文件中
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'
}
回答by Mahendran Candy
Surely it will work
肯定会起作用
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt' }
回答by aMighty
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
我的应用程序遇到了同样的问题。您需要确保没有两次添加任何库。如果您遵循了 firebase 文档 https://firebase.google.com/docs/android/setup
Then you should not add firebase library inside android studio i.e. file->project structure->cloud->firebase
那么你不应该在android studio中添加firebase库,即文件->项目结构->云->firebase
You have to do only one of the both, to use firebase in your android application.
您只需执行两者之一,即可在您的 android 应用程序中使用 firebase。
At the end clean and rerun your app.
最后清理并重新运行您的应用程序。
回答by S.sadham hussain
I think you need to include only these options in build.gradle:
我认为您只需要在 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'
}
}