使用 Jenkins 构建 Android 项目抛出 com.android.dex.DexException 而命令行构建可能工作

Building Android project using Jenkins throws com.android.dex.DexException while command line building works probably

我正在使用命令 ant clean debug emma install test 从命令中使用 Apache Ant 构建我的 Android 项目行,一切正常(测试工作和构建成功)。虽然用于 Jenkins 构建的相同命令(配置了 ANT、JAVA、ANDROID_SDK)在最后的构建步骤中抛出错误:

[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
   [dx] Result compacted from 9251,1KiB to 7638,5KiB to save 1612,5KiB
   [dx] Merged dex A (5330 defs/5673,8KiB) with dex B (2032 defs/1984,5KiB). Result is 7362 defs/7638,5KiB. Took 0,6s
   [dx] com.android.dex.DexException: Multiple dex files define Lcom/vladium/app/IAppVersion;
   [dx]     at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
   [dx]     at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
   [dx]     at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
   [dx]     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
   [dx]     at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
   [dx]     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
   [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
   [dx]     at com.android.dx.command.dexer.Main.run(Main.java:246)
   [dx]     at com.android.dx.command.dexer.Main.main(Main.java:215)
   [dx]     at com.android.dx.command.Main.main(Main.java:106)
BUILD FAILED
/SDK/android-sdk-macosx/tools/ant/build.xml:892: The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:894: The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:899: The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:283: null returned: 2

Jenkins 在我的本地机器上托管(它从命令行完美地构建了这个项目),我很困惑,为什么会出现这个错误。使用 emma.jar 看起来很麻烦,但我找不到如何修复 Jenkins 中的构建项目。

有什么想法吗?

找到解决办法。我们必须执行命令(单词的顺序很重要):

ant clean emma debug install test

并从我们的类路径(libs 文件夹)中排除任何 emma 库。一切都很简单。