如何修复“生成最终存档时出错:重复条目:AndroidManifest.xml”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2934185/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:57:47  来源:igfitidea点击:

How to fix "Error generating final archive: duplicate entry: AndroidManifest.xml"

androidandroid-manifest

提问by pyleaf

I put two projects into Eclipse, called Project1 and Project2.

我在 Eclipse 中放入了两个项目,分别称为 Project1 和 Project2。

Project1 is independent, but Project2 must be dependent to Project1.

Project1 是独立的,但 Project2 必须依赖于 Project1。

When I build the Project2, the error msg comes like this: Error generating final archive: duplicate entry: AndroidManifest.xml

当我构建 Project2 时,错误消息是这样的:生成最终存档时出错:重复条目:AndroidManifest.xml

回答by Matt Huggins

I figured out what the problem was. I included a JAR file that had an AndroidManifest.xml file in it, which was conflicting with my own project's AndroidManifest.xml file. The solution in my instance was to rebuild the JAR file, making sure it excluded its own version of AndroidManifest.xml, then to re-include the new version of the JAR file into my project. You might need to clean the project after doing this.

我想出了问题所在。我包含了一个 JAR 文件,其中有一个 AndroidManifest.xml 文件,它与我自己项目的 AndroidManifest.xml 文件冲突。我的实例中的解决方案是重建 JAR 文件,确保它排除了自己的 AndroidManifest.xml 版本,然后将新版本的 JAR 文件重新包含到我的项目中。执行此操作后,您可能需要清理项目。

回答by GMG

I had got the same problem some days ago, if you put a JAR inside libs folder and the JAR has inside a AndroidManifest.xml you got the error. If you put the JAR outside the project (for example on desktop) and in "java Build Path" you use "Add external JAR" the problem is solved.

几天前我遇到了同样的问题,如果你把一个 JAR 放在 libs 文件夹中,而 JAR 有一个 AndroidManifest.xml 你会得到错误。如果您将 JAR 放在项目之外(例如在桌面上)并且在“java Build Path”中使用“Add external JAR”,问题就解决了。

回答by duongvanthai

I think you use Project1 as Library. So, when you export jar file you should unselect AndroidManifest.xml on "Select the resource to export".

我认为您使用 Project1 作为库。因此,当您导出 jar 文件时,您应该在“选择要导出的资源”上取消选择 AndroidManifest.xml。

回答by user1378052

I got a second (ungracefull) AndroidManifest.xml file by including an Android.R package instead of the com.example.mypackage.R.

通过包含一个 Android.R 包而不是 com.example.mypackage.R,我得到了第二个(不完整的)AndroidManifest.xml 文件。

Symptoms: build seemed to work, but launching showed the existing Error in workspace, which needed to be fixed first. One AndroidManifest.xml was found in classes, the other in a file called resources.ap_ . I simply quickfixed (include android.R) workspace to hell.

症状:构建似乎有效,但启动显示工作区中存在错误,需要先修复。一个 AndroidManifest.xml 位于类中,另一个位于名为 resources.ap_ 的文件中。我只是快速修复(包括 android.R)工作区到地狱。

edit: didn't work either, workspace still in in hell; problems in projects, which liked to be fixed...

编辑:也没有用,工作区还在地狱里;项目中的问题,喜欢修复......

edit1: can't find the package, with should hold the AndroidManifest.xml.

编辑1:找不到包,应该保存AndroidManifest.xml。

edit2: I consider to assume the second Manifest File in Android.jar - seems like each Manifest file results in generated 1 R.class. I erased complete workspace. Because it was playground anyway. (Then I set up Git.)

edit2:我考虑假设 Android.jar 中的第二个 Manifest 文件 - 似乎每个 Manifest 文件都会生成 1 个 R.class。我擦除了完整的工作区。因为无论如何它都是游乐场。(然后我设置了 Git。)

回答by kmchugh12

It is possible that you have similar compile time dependencies in your library project and your application project and the dex-er is not recognizing the duplicates.

您的库项目和应用程序项目中可能有类似的编译时依赖项,并且 dex-er 无法识别重复项。

If this is the case change the scope of the dependencies in your application project to the provided scope.

如果是这种情况,请将应用程序项目中的依赖项范围更改为提供的范围。

The dependencies will be included because they are in the library project, and they will not be duplicated because they are "provided" when compiling the application project.

依赖会被包含,因为它们在库项目中,它们不会被复制,因为它们是在编译应用程序项目时“提供”的。

回答by Nabin

You will get a series of error message related to AndroidManifest, main.xml, activity_main. So the best solution would be, renamethem (using shift+ctrl+R) from one of the project to something else.

您将收到一系列与AndroidManifest、main.xml、activity_main相关的错误消息。因此,最好的解决方案是,它们(使用 shift+ctrl+R)从项目之一重命名为其他名称。

This solved my problem.

这解决了我的问题。

回答by m0skit0

I could only fix it in Android Studio by deleting the out/ directory and letting it re-build everything again.

我只能在 Android Studio 中通过删除 out/ 目录并让它重新构建所有内容来修复它。

回答by Seva Alekseyev

Cleaning the Project1 might help.

清洁 Project1 可能会有所帮助。