简体   繁体   English

无法使用Dagger 2依赖项从命令行构建Android Gradle项目

[英]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.

相关问题 无法从 Android 项目中的 gradle 中删除传递依赖 - Not able to remove transitive dependency from gradle in an Android Project 在使用Android工作室项目的命令行上使用Gradle构建失败:Xlint错误 - Failure on build with Gradle on command line with an android studio project : Xlint error 如何在命令行中为新的Android项目构建gradle - How to build gradle for a new android project in command line 从命令行构建android项目 - Build android project from command line 无法使用黄油刀依赖构建 android 项目 - not able to build android project with butterknife dependency 如何从命令行使用 gradle 创建 android 项目? - How to create android project with gradle from command line? 从命令行创建gradle创建android项目? - create android project with gradle from command line deprecated? 如何在Android项目中从头开始设置DAGGER依赖注入? - How to set up DAGGER dependency injection from scratch in Android project? android gradle内置命令行错误:UnsupportedClassVersionError - android gradle build in command line error: UnsupportedClassVersionError 使用Gradle的Android构建中包含另一个依赖项目时,错误“无法解析项目” - Error “could not resolve project” when including a dependency project from another for an Android build with Gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM