android - 如何在 android studio 3.1.2 中启用注释处理器
问题描述
我正在为我的 android 应用程序使用 dagger 2 库,但它不会生成 Daggercomponent 类,所以我读到我应该启用注释处理器,但我在 android studio 3.1.2 的任何地方都找不到它,它不在设置中我也添加了这个gradle的代码并没有帮助
javaCompileOptions{
annotationProcessorOptions {
includeCompileClasspath true
}
}
请注意我说的是 3.1.2 版本。在以前的版本中,注释处理器在菜单中,但我在这个版本中找不到它
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.moein.volley_download_kotlin"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions{
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
implementation 'com.tonyodev.fetch2downloaders:fetch2downloaders:2.0.0-RC21'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
}
(我在 github 上的 dagger 实现代码不想在这里重写:https ://github.com/codepath/android_guides/issues/331 )
解决方案
如果您在项目中使用 kotlin,则需要使用 kotlin 注释处理器。将其添加到 gradle 文件的开头:
apply plugin: 'kotlin-kapt'
而不是使用annotationProcessor
use kapt
:
kapt 'com.google.dagger:dagger-compiler:2.13'
kapt 'com.google.dagger:dagger-android-processor:2.13'
我正在检查你的匕首设置,这个模块似乎有点不对劲:
@Module
class globals {
lateinit var volleyinstance:VolleyController
fun golobals(volley:VolleyController){
volleyinstance=volley
}
@Provides
@Singleton
fun provideVolley():VolleyController{
return volleyinstance
}
}
我没有看到您的 volleyController 在任何其他模块中创建。也许你想做类似的事情:
@Module
class globals {
@Provides
@Singleton
fun provideVolley():VolleyController{
return VolleyController()
}
}
推荐阅读
- javascript - 如何将可折叠表单添加到 PHP 代码中的编辑按钮?我尝试了一些东西,但没有用
- python-3.x - 从从发布请求收到的 iframe 响应中解析 src 链接
- c++ - 打印数组中非连续元素的最大和的解
- r - 定义具有常数数值的矩阵
- python - 绘制两个系列数据
- python - 了解返回语句中的打印
- reactjs - 输入'{匹配:任何;}' 不可分配给类型 '(props: RouteComponentProps
) => 反应节点 - python - 从函数返回多条数据的问题
- javascript - 为什么无限递归异步函数不会导致堆栈溢出?
- c - 如何分割图像并将其保存在一维数组中