Android上的Dagger 2,缺少错误消息 [英] Dagger 2 on Android, missing error messages
问题描述
我在Android项目中使用了Dagger 2,但调试时遇到了麻烦.我知道编译是由于我的Dagger 2安装程序中的错误(之前有过)而失败的,但是几乎找不到它,因为我没有得到正确的错误消息来告诉我问题出在哪里.我得到的都是表明注释处理失败的消息.遵循以下原则:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(14, 28) error: cannot find symbol class BR
Error:(17, 40) error: package com.some.package.databinding does not exist
Error:(17, 51) error: cannot find symbol class DaggerSomeComponent
...
也许这与我也在使用数据绑定这一事实有关!?
我正在使用Dagger 2.5,Gradle插件2.1.2和android-apt 1.8.
感谢您的帮助!
Java
javac
默认情况下最多只会显示100个错误.您可能超出了此限制,因为数据绑定报告了它生成的每个绑定类的错误.
将此添加到应用程序的build.gradle
:
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}
科特林
使用kapt
时,可以通过将以下内容添加到build.gradle中来启用相同的javac选项.
kapt {
javacOptions {
option("-Xmaxerrs", 500)
}
}
当前已被忽略,但将在Kotlin v1.2.20
中被已修复./p>
I'm using Dagger 2 in my Android project and I'm having trouble debugging it. I know that the compilation fails because of an error in my dagger 2 setup (had it before) but it's almost impossible to track it down because I don't get a proper error message telling me where the problem lies. All I get are messages that show that the annotation processing failed. Along the lines of:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(14, 28) error: cannot find symbol class BR
Error:(17, 40) error: package com.some.package.databinding does not exist
Error:(17, 51) error: cannot find symbol class DaggerSomeComponent
...
Maybe it's somehow related to the fact that I'm also using databinding!?
I'm using Dagger 2.5, Gradle plugin 2.1.2 and android-apt 1.8.
Thanks for your help!
Java
javac
by default will only show up to 100 errors. You are probably over this limit because of databinding reporting an error for each binding class it generates.
Add this to your apps's build.gradle
:
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}
Kotlin
You can enable the same javac option when using kapt
by adding the following to your build.gradle.
kapt {
javacOptions {
option("-Xmaxerrs", 500)
}
}
This is currently ignored, but will be fixed in Kotlin v1.2.20
.
这篇关于Android上的Dagger 2,缺少错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!