AndroidAnnotations and Dagger

2019-04-22 07:06发布

I'm trying to use Dagger to inject into an android Annotated Activity.

java.lang.IllegalArgumentException: No inject registered for members/com.app.server.AddServerActivity_. You must explicitly add it to the 'injects' option in one of your modules.

If I try and Add the com.app.server.AddServerActivity_ to the module I get a diffrent error

Error: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class
java.lang.RuntimeException: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class
    at com.sun.tools.javac.main.Main.compile(Main.java:469)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
    at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:167)
    at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:364)
    at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:276)
    at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:190)
    at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:162)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1018)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:742)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:790)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:705)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:526)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:314)
    at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:179)
    at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:220)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:112)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:132)
    at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class
    at com.sun.tools.javac.model.AnnotationProxyMaker$ValueVisitor.visitArray(AnnotationProxyMaker.java:190)
    at com.sun.tools.javac.code.Attribute$Array.accept(Attribute.java:215)
    at com.sun.tools.javac.model.AnnotationProxyMaker$ValueVisitor.getValue(AnnotationProxyMaker.java:165)
    at com.sun.tools.javac.model.AnnotationProxyMaker.generateValue(AnnotationProxyMaker.java:143)
    at com.sun.tools.javac.model.AnnotationProxyMaker.getAllReflectedValues(AnnotationProxyMaker.java:101)
    at com.sun.tools.javac.model.AnnotationProxyMaker.generateAnnotation(AnnotationProxyMaker.java:86)
    at com.sun.tools.javac.model.AnnotationProxyMaker.generateAnnotation(AnnotationProxyMaker.java:78)
    at com.sun.tools.javac.model.JavacElements.getAnnotation(JavacElements.java:108)
    at com.sun.tools.javac.model.JavacElements.getAnnotation(JavacElements.java:121)
    at com.sun.tools.javac.code.Symbol$ClassSymbol.getAnnotation(Symbol.java:888)
    at dagger.internal.codegen.ValidationProcessor.validateProvides(ValidationProcessor.java:75)
    at dagger.internal.codegen.ValidationProcessor.process(ValidationProcessor.java:67)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    ... 24 more

Edit: ok, it seems to be a known issue with how dagger deals with classes generated by other processors.

https://github.com/square/dagger/issues/322

2条回答
干净又极端
2楼-- · 2019-04-22 07:13

I suggest you use Dagger2, whose usage seems more "natural".

查看更多
戒情不戒烟
3楼-- · 2019-04-22 07:24

This issue was fixed as of commit 709a48b of Dagger.

Collaborator cgruber commented Nov 13, 2013

This has been validated in two places, so I'm closing this issue.

Still, using Dagger2, which is a joint effort of google and square, seems a good idea.

查看更多
登录 后发表回答