google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.42k stars 2.01k forks source link

Dagger 2.10-rc1 won't compile in Android #593

Closed emarc-m closed 7 years ago

emarc-m commented 7 years ago

I wanted to try the new features for activity and fragment injection in dagger.android but I get this gradle error stack trace when trying to update from v2.9 -> 2.10-rc1

`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:775) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741) at com.android.dx.command.dexer.Main.access$1200(Main.java:88) at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683) 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:173) 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:787) at com.android.dx.command.dexer.Main.access$1600(Main.java:88) at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722) at com.android.dx.command.dexer.Main.processClass(Main.java:773) ... 16 more

warning: Ignoring InnerClasses attribute for an anonymous inner class (autovalue.shaded.org.apache.commons.lang.builder.HashCodeBuilder$1) 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. warning: Ignoring InnerClasses attribute for an anonymous inner class (autovalue.shaded.org.apache.commons.lang.builder.ToStringStyle$1) 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. 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:775) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741) at com.android.dx.command.dexer.Main.access$1200(Main.java:88) at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683) 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:587) 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:173) 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:787) at com.android.dx.command.dexer.Main.access$1600(Main.java:88) at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722) at com.android.dx.command.dexer.Main.processClass(Main.java:773) ... 16 more `

is 2.10-rc1 not compatible with Android or is there configuration I need do?

Thanks.

LuigiPapino commented 7 years ago

are you using retrolambda?

JakeWharton commented 7 years ago

It's not a Retrolambda problem. The classfiles in the artifact were compiled with a target of Java 8.

ronshapiro commented 7 years ago

This should be fixed in rc2 shortly

LuigiPapino commented 7 years ago

Perfect, thanks very much

bubenheimer commented 7 years ago

@ronshapiro - once RC2 is out, could you share how you built it? (Unless it's more obvious at that point.) I tried and failed to build the dagger artifacts with a target of JDK 1.7, to better evaluate RC1.

ronshapiro commented 7 years ago

Assuming you have bazel installed, it's just bazel build //java/dagger/android and bazel build //java/dagger/android/support. If you're asking how to install it into maven local, you'd have to do something similar to the util/execute-deploy.sh script.

On Thu, Feb 23, 2017, 5:48 PM Uli Bubenheimer notifications@github.com wrote:

@ronshapiro https://github.com/ronshapiro - once RC2 is out, could you share how you built it? (Unless it's more obvious at that point.) I tried and failed to build the dagger artifacts with a target of JDK 1.7, to better evaluate RC1.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/593#issuecomment-282147367, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwY3WgvhTPLxaqaIA5yEiH0AzYFbaDBks5rfgzYgaJpZM4MJvdo .

bubenheimer commented 7 years ago

Thanks - pretty sure that's what I did in terms of bazel build. It generated 1.8 artifacts. Had trouble figuring out how make Bazel generate 1.7 targets, but once I settled for passing through javac command-line options via --javacopt, I was not able to build dependencies that were using Java 8 source style. Hoping it will change with RC2.

bubenheimer commented 7 years ago

I think I found my error. I mistakenly thought that my hand-built Dagger Android libraries were the issue, when the real problem was the official plain dagger RC1 artifact from Maven. Thanks for the pointer!

Modulo216 commented 7 years ago

Any update on when we can expect RC2?

ronshapiro commented 7 years ago

@Modulo216 I'm building it right now actually :)

ronshapiro commented 7 years ago

Should be live (but Sonatype seems slow today)

JonathanMerritt commented 7 years ago

I've been having this same issue.

I tested out RC2 and unfortunately the issue has persisted. I reverted to using a local android package and 2.9. However if you need more info for the setup or logs just let me know.

JakeWharton commented 7 years ago

RC2 classes are not compiled to v52.

On Fri, Mar 3, 2017, 7:55 PM Jon Merritt notifications@github.com wrote:

I've been having this same issue.

I tested out RC2 and unfortunately the issue has persisted. I reverted to using a local android package and 2.9. However if you need more info for the setup or logs just let me know.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/593#issuecomment-284111230, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEESKHO_OqIirYd7CPtwpmrPmiHtPCks5riLaTgaJpZM4MJvdo .

JonathanMerritt commented 7 years ago

@JakeWharton I apologise if I sound uninformed but I'm very much a novice still...

You're saying the new build isn't J8 ready basically? Parsing byte code is well beyond my understanding sorry.

JakeWharton commented 7 years ago

RC1 was compiled requiring a Java 8 runtime or newer whereas RC2 only requires Java 6 or newer. What makes you say the issues has persisted? Dex is still complaining when you use RC2?

On Fri, Mar 3, 2017, 8:33 PM Jon Merritt notifications@github.com wrote:

@JakeWharton https://github.com/JakeWharton I apologise if I sound uninformed but I'm very much a novice still...

You're saying the new build isn't J8 ready basically? Parsing byte code is well beyond my understanding sorry.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/593#issuecomment-284115333, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEESgNk6q3iehDNQm2cer4e3ug-ncJks5riL9fgaJpZM4MJvdo .

JonathanMerritt commented 7 years ago

Yes it gives me the same error as the OP.

'Dec cannot parse version 52... ... targetCompatibilty=1.7...'

My setup is similar as well, I'm using retroLambda etc...

I'll be happy to make a fresh project and get what info you may need.

JakeWharton commented 7 years ago

Can you show all the lines in your build.gradle that include 'dagger'?

On Fri, Mar 3, 2017 at 8:41 PM Jon Merritt notifications@github.com wrote:

Yes it gives me the same error as the OP.

'Dec cannot parse version 52... ... targetCompatibilty=1.7...'

My setup is similar as well, I'm using retroLambda etc...

I'll be happy to make a fresh project and get what info you may need.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/593#issuecomment-284116143, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEU0p-qA_4X71S8hIAVOJ6PXThpGFks5riMFYgaJpZM4MJvdo .

JonathanMerritt commented 7 years ago

`build.gradle ... dependencies { def dagger2 = '2.10-rc2'

compile "com.google.dagger:/dagger:${dagger2}" compile "com.google.dagger:dagger-android:${dagger2}" compile "com.google.dagger:dagger-android:support:${dagger2}"

annotationProcessor "com.google.dagger:dagger-compiler:${dagger2}"

annotationProcessor "com.google.dagger:dagger-android:processor${dagger2}" - Unsure if this is needed, error is the same with or without however. `

JakeWharton commented 7 years ago

That syntax is invalid so I suspect your build is not actually picking up the new artifacts. Try this:

compile "com.google.dagger:dagger:${dagger2}"
compile "com.google.dagger:dagger-android:${dagger2}"
compile "com.google.dagger:dagger-android-support:${dagger2}"

annotationProcessor "com.google.dagger:dagger-compiler:${dagger2}"
annotationProcessor "com.google.dagger:dagger-android-processor:${dagger2}"
JonathanMerritt commented 7 years ago

Thank you. I will report back as soon as I can. That must be the issue though. Surprised the way I was doing it picked up at all...

That / in there was because I didn't know how to stop the little dagger icon from replacing the word.

Anyway, I'll be able to test this again soon and I'll let you know, thank you again.

JonathanMerritt commented 7 years ago

@JakeWharton

All set. That was exactly it. You're like a laser with this stuff. Thank you for this, and all you've taught me too.

Sorry for all the notifications everyone.

numerouno979 commented 7 years ago

Still facing this issue with 2.9 artifact deployed on maven central. Attached is screen shot of manifest.mf file dagger2 9-manifest mf

ronshapiro commented 7 years ago

What about 2.11-rc2?

numerouno979 commented 7 years ago

Still reproducible with '2.11-rc2', even with 2.10

rakshakhegde commented 7 years ago

I'm using 2.11-rc2 in this repo and it works fine