6

I have a project that builds ok in Eclipse but throws a ZipException when executing "ant debug". The output is the following (paths and project name excluded)

    -dex:
      [dex] Converting compiled files and external libraries into /home/.../Android/[folder]/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.util.zip.ZipException: error in opening zip file
       [dx]     at java.util.zip.ZipFile.open(Native Method)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:148)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:206)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx]     at com.android.dx.command.Main.main(Main.java:95)
       [dx] 1 error; aborting

BUILD FAILED
/home/.../android-sdk-linux_x86/tools/ant/build.xml:818: The following error occurred while executing this line:
/home/.../android-sdk-linux_x86/tools/ant/build.xml:820: The following error occurred while executing this line:
/home/.../android-sdk-linux_x86/tools/ant/build.xml:832: The following error occurred while executing this line:
/home/.../android-sdk-linux_x86/tools/ant/build.xml:278: null returned: 1

This project references a library project which references another library project. So

Project A -> Project B -> Project C

To me, the weird part is that installing from eclipse everything works perfectly, but I need to be able to build the project from Ant.

I've googled for answers without success. Similar questions in SO that didn't help

How do I fix this ZipException while compiling an Android project on Jenkins?

Configuring ant to run unit tests. Where should libraries be? How should classpath be configured? avoiding ZipException

Community
  • 1
  • 1
Maragues
  • 37,861
  • 14
  • 95
  • 96
  • Did you ever solve this? I get the same issue after upgrading the SDK Tools from 16 to 19. – fejd May 25 '12 at 07:10
  • I gave up on using Android's Ant and created my own, less powerful but it did what I wanted. Also, if I remember well I eliminated the dependency between Project B and Project C and placed a "Project C.jar" in Project A. Wow, what a mess of a comment, sorry I can't help a lot – Maragues May 25 '12 at 07:25

2 Answers2

1

I was getting this same error while dexing. I found that a corrupted .jar file in an included android library project was causing this issue.

Fixing the corrupted .jar file in the included android library project fixed the issue.

Hope this helps someone! =D

prolink007
  • 33,872
  • 24
  • 117
  • 185
  • Thanks for sharing! I'm not working on this project anymore, but if people vote this up, I'll tick it as the accepted answer, even tho I don't think that was my problem. – Maragues Oct 17 '12 at 07:26
1

I had this same exact problem in my project. I found that running ant with the debug flag '-d' dumps the info needed to diagnose the problem. Ant will dump the exact dx command to the console and it looks something like this:

Execute:Java13CommandLauncher: Executing '/Users/cliff/android-sdk-macosx/platform-tools/dx' with arguments:
'--dex'
'--output'
'/Users/cliff/Src/myproject/myproject-app/bin/classes.dex'
'/Users/cliff/Src/myproject/myproject-app/bin/classes'
'/Users/cliff/Src/myproject/myproject-config/bin/classes.jar'

In my case, one of the dependent projects (myproject-config) had not been built so myproject-config/bin/classes.jar was missing. I walked into the myproject-config/ folder, ran "ant debug" then went back and was able to successfully build my project

Cliff
  • 10,586
  • 7
  • 61
  • 102