1

I made a library in intelliJ. It is a rest client that I want to import it in android project. I want to develop the library seperate in intelliJ since it lets me to test it without actual android app but just in console. When I want to the import library in the android studio I get an error. I tried all the ways of importing library (a lot of them are from SO). This is what I do:

I go to project structure, choose dependencies and add from folder in which I have .jar file that I made in intelliJ. In IntelliJ I did Artifact and then build it as .jar. I moved that to android studio and it does not work. Bellow is the error I get when trying to compile project in Android studio.

     Error:Execution failed for task ':app:preDexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Users\Gregor\AppData\Local\Android\android-studio\sdk\build-tools\android-4.4.2\dx.bat --dex --output C:\Users\Gregor\AndroidStudioProjects\Perla\app\build\pre-dexed\debug\PerlaRestAPI-985193a1adafac50f74c01c1069cd74ce9c69b55.jar C:\Users\Gregor\AndroidStudioProjects\Perla\app\libs\PerlaRestAPI.jar Error Code: 1 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388) at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251) at com.android.dx.command.dexer.Main.processClass(Main.java:665) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) ...while parsing api/Game.class 1 error; aborting

gorgi93
  • 2,457
  • 8
  • 30
  • 53

2 Answers2

3

Is your library in IntelliJ being compiled with Java 7? This may be what is causing the dex tool to fail. Android only supports Java 6.

Edit: This is no longer true as of from Android 5.0, which now requires Java 7.

  • 1
    Tjere are some java 7 features supported: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7 – Arjan Apr 26 '14 at 20:46
0

I experienced the error message bad class file magic (cafebabe) or version (0034.0000) and took the following steps to successfully solve the problem:

  • Set the language level in my Intellij module to 7
  • Set the JAR to be compiled to my Android module's libs folder
  • Right-clicked on the JAR then Add as library
  • Set sourceCompatibility and targetCompatibility to JavaVersion.VERSION_1_7 in the Android module's build.gradle compileOptions

One possible problem to watch out for your JAR file having dependencies which are compiled with a Java version not currently supported by Android.