这是在项目中使用kotlin开发遇见的问题
1 Unresolved reference: java
在项目的gradle中
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
}
ext.kotlin_version = '1.2.41'
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
//kotlin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
2调用kotlin 文件出现包名找不到
在app 的gradle中配置
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
3 Unresolved reference: databinding
databinding和kotlin冲突
在项目的build.gradle中
ext.android_plugin_version = '2.3.0'
下边是完整配置
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
}
ext.kotlin_version = '1.2.51'
ext.android_plugin_version = '2.3.0'
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
在app build.gradle中添加
apply plugin: 'kotlin-kapt'
android{
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
kapt {
generateStubs = true
}
dependencies {
kapt "com.android.databinding:compiler:$android_plugin_version"
}