我将 Kotlin 与 Dagger 2 一起使用。问题是,当我在实现 Dagger 时出错(例如,@Inject
类构造器的错误)时,IDE 不会具体显示错误在哪里。Insead 编译器错误总是一样的:
Execution failed for task ':app:kaptDebugKotlin'. Internal compiler error. See log for more details
故意犯错的班级(@Inject 评论):
class LoginPresenter //@Inject
constructor(private val request: LoginRequest)
项目 build.gradle 文件:
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块 build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.kravets_a.kotlinanddagger"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
...
compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
kapt "com.google.dagger:dagger-compiler:2.10"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
mavenCentral()
}