Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Barber is incompatible with Dagger code generation #6

Closed
inktomi opened this issue Mar 5, 2015 · 15 comments
Closed

Barber is incompatible with Dagger code generation #6

inktomi opened this issue Mar 5, 2015 · 15 comments

Comments

@inktomi
Copy link

inktomi commented Mar 5, 2015

Hi -

Tracking this, so I wanted to put in an issue. When adding Barber to a project that already uses Dagger (and dagger-compiler) for injection, dagger code generation fails to run.

My setup is as such;

apt 'io.sweers.barber:barber-compiler:1.0.1'
compile 'io.sweers.barber:barber-api:1.0.1'
compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
@ZacSweers
Copy link
Owner

Can you give me a little more info? Everything still builds just fine for me if I add dagger to my dependencies. A stacktrace would be useful.

@denley
Copy link

denley commented Mar 7, 2015

If more than one annotation processor is used then this also has to be added to the build config:

android {
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

You should get a warning about this though, so perhaps the issue is elsewhere.

@ZacSweers
Copy link
Owner

Ah yes, that's a good point. Would be better if @inktomi could provide some more clarification though

@inktomi
Copy link
Author

inktomi commented Mar 7, 2015

I'm so sorry. I've been out of town. I will try this tomorrow on a fresh project to ensure there was nothing else happening in mine..

@ZacSweers
Copy link
Owner

Sounds good, thanks!

@ZacSweers
Copy link
Owner

@inktomi any luck?

@inktomi
Copy link
Author

inktomi commented Mar 9, 2015

Hi, sorry for the delay.

I set up the following little test project. It shows the issue when you try to run it.

https://github.com/inktomi/BarberDagger

03-09 09:15:22.008    5388-5388/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mattruno.testdaggerbarber, PID: 5388
    java.lang.RuntimeException: Unable to create application com.mattruno.testdaggerbarber.TestApplication: java.lang.IllegalStateException: Module adapter for class com.mattruno.testdaggerbarber.ServiceModule could not be loaded. Please ensure that code generation was run for this module.
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4521)
            at android.app.ActivityThread.access$1500(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.IllegalStateException: Module adapter for class com.mattruno.testdaggerbarber.ServiceModule could not be loaded. Please ensure that code generation was run for this module.
            at dagger.internal.FailoverLoader$1.create(FailoverLoader.java:45)
            at dagger.internal.FailoverLoader$1.create(FailoverLoader.java:40)
            at dagger.internal.Memoizer.get(Memoizer.java:56)
            at dagger.internal.FailoverLoader.getModuleAdapter(FailoverLoader.java:57)
            at dagger.internal.Modules.loadModules(Modules.java:43)
            at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:174)
            at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
            at dagger.ObjectGraph.create(ObjectGraph.java:129)
            at com.mattruno.testdaggerbarber.TestApplication.onCreate(TestApplication.java:16)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518)
            at android.app.ActivityThread.access$1500(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

@ZacSweers
Copy link
Owner

I see. Have you tried @denley's solution? I'm not very familiar with Dagger, so I'm not sure where to start with this since all the code looks like it's just dagger issues.

android {
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

@inktomi
Copy link
Author

inktomi commented Mar 9, 2015

I do have that included in the gradle file for the app module.. no affect though =\

https://github.com/inktomi/BarberDagger/blob/master/app/build.gradle

@ZacSweers
Copy link
Owner

Hmm, I have no idea then. I'll try looking at it some this weekend, but no promises. Going to mark this as help wanted now as well

@denley
Copy link

denley commented Mar 9, 2015

I just had a quick look and I think I've figured it out. It's actually not an issue with Barber (the same problem occurs when you remove the Barber dependencies). It appears to be an issue with the android-apt plugin ignoring the provided dependencies.

It will work with the following configuration instead (notice the apt instead of provided for the dagger compiler dependency):

apt 'io.sweers.barber:barber-compiler:1.0.1'
compile 'io.sweers.barber:barber-api:1.0.1'
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'

@ZacSweers
Copy link
Owner

Ah interesting, so someone can't use apt and provided in the same configuration?

@denley
Copy link

denley commented Mar 9, 2015

It appears that way. The apt plugin seems to completely take over the annotation processing or something like that.

@ZacSweers
Copy link
Owner

Interesting. Well, good to know. @inktomi can I mark this as resolved then?

@inktomi
Copy link
Author

inktomi commented Mar 10, 2015

Awesome. Thanks for the team effort!!

@inktomi inktomi closed this as completed Mar 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants