我正在使用Android Studio 3.0 Canary 6版本。我已经在我的类中启用了dataBinding,代码没有显示任何错误。但是,当我构建APK时,构建失败并显示以下错误:
Error:(8, 37) Unresolved reference: databinding
Error:(22, 26) Unresolved reference: ActivityMainBinding
Error:(38, 50) Unresolved reference: ActivityMainBinding
Error:(43, 52) Unresolved reference: ActivityMainBinding
Error:(46, 52) Unresolved reference: ActivityMainBinding
Error:(49, 52) Unresolved reference: ActivityMainBinding
Error:(52, 52) Unresolved reference: ActivityMainBinding
Error:(55, 52) Unresolved reference: ActivityMainBinding
Error:(58, 52) Unresolved reference: ActivityMainBinding
Error:(61, 52) Unresolved reference: ActivityMainBinding
Error:(64, 52) Unresolved reference: ActivityMainBinding
Error:(67, 52) Unresolved reference: ActivityMainBinding
Error:(70, 52) Unresolved reference: ActivityMainBinding
Error:(73, 52) Unresolved reference: ActivityMainBinding
Error:Execution failed for task ':app:compileDebugKotlin'.
Compilation error. See log for more details
顶级build.gradle文件如下:
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
下面是module build.gradle文件的内容:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.jimil.calculator"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
dataBinding{
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation ('com.android.support.test.espresso:espresso-
core:3.0.1', {
exclude group: 'com.android.support', module: 'support-
annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
kapt 'com.android.databinding:compiler:3.0.0-alpha6'
}
kapt {
generateStubs = true
}
MainActivity.kt类是:
import com.example.jimil.calculator.databinding.ActivityMainBinding
...
class MainActivity : AppCompatActivity() {
private var binding: ActivityMainBinding? = null
...
}
请帮我解决构建错误。