この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
Kotlin 1.0.4でAPTの設定が変わりました。
Kotlin 1.0.4 is here | Kotlin BlogのNew Experimental Annotation Processingの部分がその記述です。
dagger2を例に説明します。
app/build.gradleの設定
Dagger2をKotlinで使うためには以下のように設定します。 記述だけ変わった感じです。
+ が1.0.4で必要になった設定
- が1.0.3までの設定です。
app/build.gradleの設定
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
+ apply plugin: 'kotlin-kapt'
gradle</code>
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.kamei.kotlinsample"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
- kapt {
- generateStubs = true
- }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger:2.6.1'
kapt 'com.google.dagger:dagger-compiler:2.6.1'
}