-1

I have created a Jar in Intellij. Jar contains following folder.file:....

  1. okio
  2. meta-inf->maven
  3. com -> google, squareup, xyz,

I am trying to use the Jar in Android project. After compilation it gives following error in android studio:....

**Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
 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:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
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:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/abc/xyz/Filename.class
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1 Information:BUILD FAILED Information:Total time: 2.741 secs Information:1 error**

My build.gadle file looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.livquik.myapplication"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile files('libs/JavaJar.jar')
}
manish
  • 944
  • 2
  • 14
  • 27

2 Answers2

1

please check this link for bad class file magic (cafebabe) or version error in android studio.better you can get the right solution

Community
  • 1
  • 1
RamBabu Pudari
  • 912
  • 7
  • 19
0

1.) Custom .jar files you are creating in eclipse are tricky. I had a number of files being read from within the jar. Moving these files away from the main folder of the jar file is a good idea (i.e. Do not place them at the same folder level as the folders: com, Meta-inf). I moved mine into the same place as the actual compiled class files.


2.) When compiling the .jar file, make sure you change the compiler to JRE 1.6. Compiling with this setting was also a factor that led to my eventual success.

TO CHANGE COMPILER COMPLIANCE:

In Eclipse, right-click on your project. Click on properties (it should be near the bottom of the right-click box). In the properties dialog box, select Java Compiler from the list on the left. You may need to uncheck Use compliance from Execution environment... in order for the drop down box to become enabled. Change the Compiler Compliance Level to 1.6, click apply and ok.

FINALLY

Recompile, re-copy and import the library into your android project and hopefully that should fix it.

Tavo
  • 3,087
  • 5
  • 29
  • 44