4

I need to build my Android application using the command line, when I get to the point that I must use dx.bat to convert to Dalvik bytecode

dx.bat --dex --output=C:/local_programs/testProject/bin/classes.dex C:/local_programs/testProject/bin/classes/test/Android/cmd/

This path "C:/local_programs/testProject/bin/classes/test/Android/cmd/" is where my .class are.

it gives me this error

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing AndroidTestActivity.class
...while processing AndroidTestActivity.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R$attr.class
...while processing R$attr.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R$drawable.class
...while processing R$drawable.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R$id.class
...while processing R$id.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R$layout.class
...while processing R$layout.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R$string.class
...while processing R$string.class

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing R.class
...while processing R.class
7 warnings
no classfiles specified

My .class are generated as they should, and as far as I can tell, they're not corrupted.

I found several instance of this problem, but none of them fit my settings since I don't use build.xml (which I understand is a ant builder)

My questions is : Do I have a choice in using ant or not ?

TurnsCoffeeIntoScripts
  • 3,868
  • 8
  • 41
  • 46
  • possible duplicate of [Android emulator crash: "Dx bad class file magic" / ClassNotFoundException on startup?](http://stackoverflow.com/questions/8748977/android-emulator-crash-dx-bad-class-file-magic-classnotfoundexception-on-st) –  Jan 05 '12 at 22:36

1 Answers1

15

Your classes need to be compiled with jdk 5 or 6. You are probably using 7. If that doesn't work, you might also need to make sure that every single class is compiled right, even if in different projects. Solved my problem here.

Community
  • 1
  • 1
user1132959
  • 978
  • 8
  • 16
  • Indeed, this solved it for me too. Just for future reference: someone else claimed that [changing `proguard.bat` fixed it](http://stackoverflow.com/questions/7866723/dx-bad-class-file-magic-cafebabe-or-version-0033-0000-with-adk14/8134277#8134277) instead. That did NOT work for me, but it might help others in other situations. – Arjan Mar 14 '12 at 09:25
  • This worked for me as well. My ant build outputted these errors ("bad class file magic...") but built successfully, then crashed on a ClassDefNotFoundException. Turns out a re-compile of the jar that was causing the problem using JDK 6 solved it. – grant Apr 12 '13 at 13:35