[英]Not able to build Android gradle project from command line with dagger 2 dependency
I've bee using dagger for a while and now I'm facing a problem related to the generation of DaggerAppComponent class. 我曾经使用dagger了一段时间,现在我面临着与DaggerAppComponent类的生成有关的问题。
It is working as expected while running the project from Android Studio, but whenever I run the task assembleDebug on command line on the root dir, gradle cannot build the entire project since dagger classes are not being generated. 从Android Studio运行项目时,它按预期方式工作,但是每当我在根目录的命令行上运行任务assembleDebug时,由于未生成dagger类,gradle无法构建整个项目。
I am missing some task in order to completly execute the dagger annontation processor? 我缺少某些任务以完全执行匕首注释处理器吗?
Dependencies: 依存关系:
final DAGGER_VERSION = '2.0.1'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'org.glassfish:javax.annotation:10.0-b28'
This is the final error: 这是最后的错误:
import com.company.injection.DaggerAppComponent;
^
symbol: class DaggerAppComponent
location: package com.company.injection
:mobile:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mobile:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/co
mmon/collect/SetMultimap;
Just to make sure, the graph is ok and it is working correctly, the problem just happen if I try to build the project by command line with assembleDebug. 只是为了确保该图正常并且可以正常工作,如果我尝试使用assembleDebug通过命令行构建项目,就只会出现该问题。
After spending some time on this, I fixed the problem adding the guava dependency as the annotationProcessor just above the dagger-compiler. 花了一些时间之后,我解决了在dagger-compiler 上方添加guava依赖项作为注解处理器的问题。
final DAGGER_VERSION = '2.0.1'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
annotationProcessor 'com.google.guava:guava:19.0'
annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'org.glassfish:javax.annotation:10.0-b28'
I had the same config with 'com.google.guava:guava:19.0'
but I was having the following error: 我与'com.google.guava:guava:19.0'
具有相同的配置,但出现以下错误:
Error:Execution failed for task ':mobile:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap;
I tried to update the guava version to the current at the time 'com.google.guava:guava:22.0'
but the error continued. 我试图在'com.google.guava:guava:22.0'
时将番石榴版本更新为当前版本,但错误仍然存在。
I changed to 'com.google.guava:guava:21.0'
and it worked nicely. 我更改为'com.google.guava:guava:21.0'
,效果很好。 May be an incompatibility with others versions. 可能与其他版本不兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.