I'm trying to implement data binding in my app and failing miserably. I can't seem to find anyone with a similar problem, so I'm hoping someone here has an idea as to why this is happening.
When I follow this tutorial from Android Kotlin Fundamentals with the provided starter app, data binding works perfectly, no problems at all. But when I do the same thing in my own project, it won't compile. I think there is something wrong with generating the needed files.
From what I've gathered, it has something to do with the compile sdk version. If I make a new project with this build.gradle file, everything works, so I know it's not a spelling error or a missing tag.
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"defaultConfig {
applicationId "com.example.databinding"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
dataBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
BUT! When I update things according to Android Studio's recommendations, everything stops working. These are the only things that change in the file:
compileSdkVersion 31
targetSdkVersion 31
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
I can see data binding related folders/files appear in app > build > generated in file explorer, so there is something happening, but nothing shows up in Android Studio. I've tried everything mentioned here. How can I fix this?