Realm-java: Realm 1.0.1 and Jacoco, error building Dex

Created on 22 Jun 2016  路  22Comments  路  Source: realm/realm-java

Using the new 1.0.1 version of Realm, with last tool 24, running ./gradlew createDebugCoverageReport gives the following error:

PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/Generated.class
PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/PostConstruct.class
PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/PreDestroy.class
PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/Resource.class
PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/Resource$AuthenticationType.class
PARSE ERROR:
unsupported class file version 52.0
...while parsing javax/annotation/Resources.class
6 errors; aborting
:app:transformClassesWithDexForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

Using sourceCompatility to java 1.7 doesn't fix the problem.
I'm not sure what is the problem here (either a bad dependency, android gradle plugin that needs to be updated, jacoco, etc...)

T-Help

Most helpful comment

@stk1m1 sorry for the late reply. It is working for us. Thanks for the release.

All 22 comments

Hi @NitroG42 Have you enabled the Jack compiler?

Nope ! (it seems it doesn't compile at all with jack anyway)

Here is the build.gradle of an empty project that got the error:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
    }
    ext.kotlin_version = '1.0.3-eap-30'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
        classpath "io.realm:realm-gradle-plugin:1.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.myapp.myapplication"
        minSdkVersion 23
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'
//    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support:support-annotations:24.0.0'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
    mavenCentral()
}

Can you try with 1.0.0 of Realm?

Oh yeah sorry that I didn't mention it before, it works with Realm 1.0.0, which is the solution I use for now ! As I said, I don't really think that you made something wrong in your 1.0.1 release, but it might be useful to found the "real" culprit.

I reproduced this on my machine.

With Realm-java 1.0.0

...
:app:generateDebugAndroidTestSources
:app:dataBindingExportBuildInfoDebugAndroidTest
:app:incrementalDebugAndroidTestJavaCompilationSafeguard
:app:compileDebugAndroidTestJavaWithJavac
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
:app:prePackageMarkerForDebugAndroidTest
:app:transformClassesWithRealmTransformerForDebugAndroidTest
:app:transformClassesWithDexForDebugAndroidTest
Result compacted from 4886.6KiB to 3840.5KiB to save 1046.1KiB
Merged dex #1 (2 defs/1.0KiB)
Merged dex #2 (22 defs/37.8KiB)
Merged dex #3 (108 defs/113.8KiB)
Merged dex #4 (2001 defs/2160.4KiB)
Merged dex #5 (3 defs/1.5KiB)
Merged dex #6 (418 defs/569.7KiB)
Merged dex #7 (9 defs/9.4KiB)
Merged dex #8 (45 defs/38.2KiB)
Merged dex #9 (5 defs/2.9KiB)
Merged dex #10 (35 defs/54.8KiB)
Merged dex #11 (2 defs/15.7KiB)
Merged dex #12 (15 defs/4.9KiB)
Merged dex #13 (286 defs/238.9KiB)
Merged dex #14 (647 defs/629.6KiB)
Merged dex #15 (30 defs/18.4KiB)
Merged dex #16 (23 defs/14.3KiB)
Result is 3651 defs/3840.5KiB. Took 0.4s
:app:mergeDebugAndroidTestJniLibFolders
...

But with Realm-java 1.0.1

...
:app:generateDebugAndroidTestSources
:app:dataBindingExportBuildInfoDebugAndroidTest
:app:incrementalDebugAndroidTestJavaCompilationSafeguard
:app:compileDebugAndroidTestJavaWithJavac
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
:app:prePackageMarkerForDebugAndroidTest
:app:transformClassesWithRealmTransformerForDebugAndroidTest
:app:transformClassesWithRealmOptionalAPITransformerForDebugAndroidTest
:app:transformClassesWithDexForDebugAndroidTest
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: Exception parsing classes
        at com.android.dx.command.dexer.Main.processClass(Main.java:761)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:727)
        at com.android.dx.command.dexer.Main.access$1200(Main.java:87)
        at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1655)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:681)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:578)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
        at com.android.dx.command.dexer.Main.run(Main.java:286)
        at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:52)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1511)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1507)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: 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.parseClass(Main.java:773)
        at com.android.dx.command.dexer.Main.access$1600(Main.java:87)
        at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1694)
        at com.android.dx.command.dexer.Main.processClass(Main.java:758)
        ... 22 more

Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: Exception parsing classes
        at com.android.dx.command.dexer.Main.processClass(Main.java:761)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:727)
        at com.android.dx.command.dexer.Main.access$1200(Main.java:87)
        at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1655)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:681)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:578)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
        at com.android.dx.command.dexer.Main.run(Main.java:286)
        at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:52)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1511)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1507)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: 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.parseClass(Main.java:773)
        at com.android.dx.command.dexer.Main.access$1600(Main.java:87)
        at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1694)
        at com.android.dx.command.dexer.Main.processClass(Main.java:758)
        ... 22 more

...

@zaki50 Have you tried with 1.1.0-SNAPSHOT? I wonder if the optional API transformer is causing this although It seems really strange if it is.

@cmelchior just 1.0.0 and 1.0.1. I'll try 1.1.0-SNAPSHOT.

I can confirm it works with 1.1.0-SNAPSHOT !

:app:assembleDebugAndroidTest UP-TO-DATE
:app:connectedDebugAndroidTest
:app:createDebugAndroidTestCoverageReport UP-TO-DATE
:app:createDebugCoverageReport UP-TO-DATE

BUILD SUCCESSFUL

Is there an ETA for 1.0.2 on jcenter?

@rimeissner We don't have ETA as we always prioritize support over development ;-)

@kneth @rimeissner In this case though 1.0.2 is a patch release, which technically is support :) ... The plan is today or tomorrow.

@cmelchior ok thanks :) I will use snapshot 1.1.0 for now

I confirmed that both 1.1.0-SNAPSHOT and 1.0.2-SNAPSHOT work.

+1 same issue, when the 1.0.2 will be released ?

@kuno We'll do a release very soon.

@kneth

Thanks a lot, can not wait for that 馃憤

Hi @NitroG42, @rimeissner, and @kuno,

Could you please upgrade to Realm 1.1.0 and see if this issue persists? There is a fix and it might solve the issue. Thanks!

Hi @NitroG42, @rimeissner, and @kuno,

Has Realm 1.1.0 sovled this issue? We'd love to find out how things are going on your side. Thanks!

@stk1m1 sorry for the late reply. It is working for us. Thanks for the release.

Hi sorry for the late reply... I didn't answer because I just quit on jacoco for now, it isn't working anymore on Mac OS X (new project, make some tests : coverage = 0%)

Hi all,

Thanks for the feedback. In case the issue arises again, please re-open this issue and inform us. We will be all ears. I am closing the issue for now. Thanks!

Was this page helpful?
0 / 5 - 0 ratings