Today I am faced with a massive error that doesn't let me run a sample project on my phone.
When Android Studio is building the project, it first shows the following targets as UP-TO-DATE
:
....
:demoproject:processDebugResources UP-TO-DATE
:demoproject:generateDebugSources UP-TO-DATE
:demoproject:compileDebugJava UP-TO-DATE
:demoproject:proguardDebug UP-TO-DATE
....
There are dozens of these UP-TO-DATE
log statements during the build process. However, they always halt at :demoproject:dexDebug
. For dexDebug
, I never seem to get an UP-TO-DATE
log statement.
Instead, dexDebug
is followed by this error:
:demoproject:dexDebug
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.xyz.corp.sample.project.demo.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
Now there are dozens of these Ignoring InnerClasses attribute
errors. They even occur for classes in the v4 support library, which is truly perplexing.
Finally, these errors end with a new statement:
UNEXPECTED TOP-LEVEL EXCEPTION:
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
Error:Execution failed for task ':demoproject:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
I have already consulted the following links:
1. Gradle finished with non-zero exit value 1.
2. What is the “Ignoring InnerClasses attribute” warning output during compilation?.
I'm not sure they apply to my situation. I'm not even able to run the project. I've updated my IDE to SDK Tools 22.0.1 and modified the buildToolsVersion
tag in my build.gradle
file, but to no avail. Can someone please guide me how to deal with this error ? All help will be appreciated.
Oh, and here is my build.gradle
:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "com.xyz.corp.demo.project"
minSdkVersion 10
targetSdkVersion 22
versionCode 2060200
versionName '2.6.02.00'
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
compile project(':xyzSDK')
}
Please HELP !!!
Because it is reporting:
bad class file magic (cafebabe) or version (0034.0000)
you should check if you are compiling with the same java version that you are trying to use at runtime. If you are using gradle you should use the following or similar entries in your build.gradle file:Use this link for more gradle details.
In Android Studio, from
File -> Project Structure -> SDK Location -> JDK Location
you should use the jdk 1.7 and not relay on theProject level
setting. See this link for a similar Android Studio question.