rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
607 stars 103 forks source link

Dex cannot parse version 52 byte code. #142

Closed jffiorillo closed 6 years ago

jffiorillo commented 7 years ago

compile 'com.ryanharter.auto.value:auto-value-gson:0.5.0'

I'm getting this error when I add the compile statement to the build.gradle

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:781)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:747)
        at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
        at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1689)
        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:695)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:560)
        at com.android.dx.command.dexer.Main.runMultiDex(Main.java:376)
        at com.android.dx.command.dexer.Main.run(Main.java:290)
        at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
        at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:174)
        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:476)
        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:793)
        at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
        at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1728)
        at com.android.dx.command.dexer.Main.processClass(Main.java:779)
        ... 16 more
ZacSweers commented 7 years ago

auto-value-gson is an extension to an annotation processor, not something you would compile in your app directly. See the download section of the README.md - https://github.com/rharter/auto-value-gson#download

jffiorillo commented 7 years ago

but this is also happening when adding the library as provided instead of compile .

ZacSweers commented 7 years ago

Then I suspect you have other libraries compiled against java 8 on your compile classpath. It's really hard to help you without a sample project that reproduces the code. Can you share one?

rharter commented 7 years ago

@hzsweers Do you recall our need for Java 8? AutoValue is set for source and target version 1.6, and I just did a quick test switching this to 1.7 and tests pass. I thought there might have been some conversation about it a while back, though.

If there is no need we could just drop the source and target compile versions to 1.7.

ZacSweers commented 7 years ago

I think just modernity. Android SDK requires Java 8 now even, which I think makes it reasonable for a general purpose Java library to use it too.

jffiorillo commented 7 years ago

I have created this PR to solve this issue: https://github.com/rharter/auto-value-gson/pull/145

ZacSweers commented 7 years ago

That doesn't really solve your issue though. You're trying to compile an annotation processor into your app currently, and brings everything with it (guava, auto libraries, etc). This would remove the build failure but doesn't change the fact that your project dependency structure seems wrong. The Android gradle plugin should/will explicitly prevent you from putting annotation processors on anything other than the annotationProcessor configuration, which will then fail your build again.

jffiorillo commented 7 years ago

In order to use the @GsonTypeAdapterFactory you need to compile or provided the library.

ZacSweers commented 7 years ago

that's fair, but the proper solution I think is for us to split the annotations out to a separate artifact like auto-value-gson. Want to make your pull request do that instead?

jffiorillo commented 7 years ago
extract_annotations_classes:josef@work:auto-value-gson$ git push --set-upstream origin extract_annotations_classes

remote: Permission to rharter/auto-value-gson.git denied to jffiorillo.
fatal: unable to access 'https://github.com/rharter/auto-value-gson.git/': The requested URL returned error: 403
ZacSweers commented 7 years ago

Yes you don't have access to push to this repo, you must do it in a fork

ZacSweers commented 6 years ago

actually - annotations are already a separate artifact. @rharter should we just lower that artifact's version to java 7?

rharter commented 6 years ago

Yeah, There's not need to require Java 8.

On December 2, 2017 at 9:27:36 PM, Zac Sweers (notifications@github.com) wrote:

actually - annotations are already a separate artifact. @rharter https://github.com/rharter should we just lower that artifact's version to java 7?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rharter/auto-value-gson/issues/142#issuecomment-348737510, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPJbkPT5pKQlN_oRpEejC5WhyUaoLuXks5s8hUngaJpZM4O7QkG .