Android 构建可以在 Eclipse 中运行,但不能在 Ant 中运行(“已添加”)
我的 Android 项目使用多个标记为 Android 库的 git 子模块。这些子模块对 ORMlite Android jar 都有不同的用途,因此 ORMlite jar 包含在它们的 libs 目录中。 Eclipse 正确处理这种情况:它在 dex 处理期间包含一次 ORMlite jar 并生成有效的 .apk,但是当我通过 ant debug 运行构建时,我得到:
[echo] Converting compiled files and external libraries into /home/webedit/.hudson/jobs/xyz/workspace/bin/classes.dex...
[apply]
[apply] UNEXPECTED TOP-LEVEL EXCEPTION:
[apply] java.lang.IllegalArgumentException: already added: Lcom/j256/ormlite/android/AndroidCompiledStatement;
[apply] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[apply] at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
[apply] at com.android.dx.command.dexer.Main.processClass(Main.java:338)
[apply] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:315)
[apply] at com.android.dx.command.dexer.Main.access$100(Main.java:56)
[apply] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:266)
[apply] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
[apply] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
[apply] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
[apply] at com.android.dx.command.dexer.Main.processOne(Main.java:284)
[apply] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:220)
[apply] at com.android.dx.command.dexer.Main.run(Main.java:176)
[apply] at com.android.dx.command.dexer.Main.main(Main.java:157)
[apply] at com.android.dx.command.Main.main(Main.java:89)
有没有办法让同一个 JAR 的多个副本分布在多个库中?我可以更改 Ant 构建设置以使其正常工作吗?
My Android project uses several git submodules marked as Android Libraries. These submodules all have different uses of the ORMlite Android jars and thus have the ORMlite jars included in their libs
directory. Eclipse handles this situation correctly: it includes the ORMlite jars once during the dex
processing and generates a valid .apk, but when I run a build via ant debug
, I get:
[echo] Converting compiled files and external libraries into /home/webedit/.hudson/jobs/xyz/workspace/bin/classes.dex...
[apply]
[apply] UNEXPECTED TOP-LEVEL EXCEPTION:
[apply] java.lang.IllegalArgumentException: already added: Lcom/j256/ormlite/android/AndroidCompiledStatement;
[apply] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[apply] at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
[apply] at com.android.dx.command.dexer.Main.processClass(Main.java:338)
[apply] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:315)
[apply] at com.android.dx.command.dexer.Main.access$100(Main.java:56)
[apply] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:266)
[apply] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
[apply] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
[apply] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
[apply] at com.android.dx.command.dexer.Main.processOne(Main.java:284)
[apply] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:220)
[apply] at com.android.dx.command.dexer.Main.run(Main.java:176)
[apply] at com.android.dx.command.dexer.Main.main(Main.java:157)
[apply] at com.android.dx.command.Main.main(Main.java:89)
Is there any way to have multiple copies of the same JAR sprinkled across multiple libraries? Is there an Ant build setting I can change to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用 maven 遇到了同样的问题,因为它正确添加了 ormlite-core-jarfile,其中包含作为 core-jar 的包和类以及一些附加类。
我添加了排除项,现在可以使用了
i got the same problem using maven because it correctly added the ormlite-core-jarfile, which contains the packages and classes as the core-jar with a few additional classes.
I added an exclusion and now it works
我通过创建第三个 Android 项目解决了我的问题,其中仅包含其他两个项目所依赖的 ORMlite JAR。
I solved my problem by creating a third Android project with only the ORMlite JAR in it that the two other projects depended on.
我的问题是,任何 ./libs 文件夹中的所有 jar 都包含在内,而不仅仅是 eclipse .classpath 中指定的那些。所以我在那里放了一些重复的东西。我只需要清理我的 ./libs。您可以通过运行“ant -v debug”(位于输出上半部分的某个位置)来找出 ant 在其“类路径”中包含的内容。
My problem was that all jars in any ./libs folder were included, not just the ones as specified in my eclipse .classpath. So I had some duplicates laying around there. I just needed to clean up my ./libs. You can find out what ant is all including in its "classpath" by running "ant -v debug", somewhere in the top half of the output.
有同样的问题,但使用 android-support-v4.jar — 它用于引用的项目库和应用程序项目。这是解决方案
解决方法:
1. 从 App/libs 中删除文件 android-support-v4.jar
2. 在 Eclipse 中添加引用 ReferencedProjectLibrary/libs/android-support-v4.jar 的 jar
它也适用于 Eclipse 和 Ant ;)
Had the same problem but with android-support-v4.jar — it was used in referenced project library and app project. Here's the solution
Workaround:
1. Remove file android-support-v4.jar from App/libs
2. In Eclipse add jar referenced to ReferencedProjectLibrary/libs/android-support-v4.jar
It works in Eclipse and Ant too ;)