我目前正在尝试新的 ViewBindings,但我没有让它们工作。我在Android Studio 3.6.1
。我刚刚创建了一个新项目并添加viewBinding.enabled = true
到我的模块build.gradle
中。但是当我尝试访问MainActivityBinding
该类时,它说它无法解析该符号。自动完成没有找到任何类似于绑定类的东西。我还尝试了一个使用 Kotlin 的不同项目,但没有成功。AS4.0
也无济于事。我需要做什么来生成ViewBinding
类?
我的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
viewBinding {
enabled = true
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}