Search code examples
androidantjenkinsemma

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


I'm using command ant clean debug emma install test to build my Android project with Apache Ant from command line and everything works perfectly (tests work and build becomes successful). While same command for Jenkins building (ANT, JAVA, ANDROID_SDK are configured) throws an error at the last build steps:

[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 hosts on my local machine (which perfectly builds this project from command line) and I'm confused, why does this error occur. Looks like trouble in using emma.jar, but I can't find out, how to fix building project in Jenkins.

Any ideas?


Solution

  • Found a solution. We must execute command (word's order is very important):

    ant clean emma debug install test
    

    and exclude any emma libraries from our classpath (libs folder). Everything is quite easy.