【发布时间】:2022-01-10 17:42:16
【问题描述】:
我的android studio版本是
Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
将IDE和kotlin更新到1.6后,我打开了一个我正在做的项目,Android Stidio将数据绑定字段标记为红色,显示如下错误:
在文本中:
Cannot access 'androidx.databinding.Observable' which is a supertype of
'com.cioccarellia.wordbucket.databinding.ActivityMainBinding'.
Check your module classpath for missing or conflicting dependencies
奇怪的是,一切都编译了,应用程序运行良好,这些错误只是在 IDE 中,每次我通过数据绑定访问视图时都会弹出。
自更新 android studio 以来,我没有更改我的依赖项。其他人对这种情况有同样的问题/解决方案吗?
主要活动 xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.cioccarellia.wordbucket.activity.MainActivity">
...
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
通用 build.gradle:
buildscript {
ext {
kotlin_version = "1.6.0"
}
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath "com.github.ben-manes:gradle-versions-plugin:0.39.0"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
应用程序 build.gradle:
plugins {
id "com.android.application"
id "kotlin-android"
id "kotlin-kapt"
id "dagger.hilt.android.plugin"
id "com.google.gms.google-services"
id "androidx.navigation.safeargs.kotlin"
id "com.github.ben-manes.versions"
id "kotlin-parcelize"
id "com.google.firebase.crashlytics"
}
android {
compileSdk 31
defaultConfig {
applicationId "com.cioccarellia.wordbucket"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
}
buildTypes {
debug {
versionNameSuffix ".dev"
}
release {
debuggable false
// Enables code shrinking, obfuscation, and optimization
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
dataBinding true
}
sourceSets {
main.res.srcDirs = [
"src/main/res",
"src/main/res-public"
]
android.sourceSets.all {
java.srcDir("src/$name/kotlin")
}
}
lintOptions {
// if set to true (default), stops the build if errors are found.
abortOnError false
// if true, only report errors.
ignoreWarnings false
}
}
dependencies {
// AndroidX
implementation "androidx.core:core-ktx:1.7.0"
implementation "androidx.appcompat:appcompat:1.4.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.2"
implementation "com.google.android.material:material:1.6.0-alpha01"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
// Lifecycle
def lifecycle_version = "2.4.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
// DI -> Hilt
implementation "com.google.dagger:hilt-android:2.40.3"
kapt "com.google.dagger:hilt-compiler:2.40.3"
// Import the Firebase BoM
implementation platform("com.google.firebase:firebase-bom:28.4.2")
// When using the BoM, you don"t specify versions in Firebase library dependencies
implementation "com.google.firebase:firebase-crashlytics-ktx"
implementation "com.google.firebase:firebase-analytics-ktx"
implementation "com.google.firebase:firebase-auth-ktx"
implementation "com.google.firebase:firebase-firestore-ktx"
// LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.7"
// Logging
implementation "com.jakewharton.timber:timber:5.0.1"
// Styles
implementation 'com.airbnb.android:paris:2.0.1'
kapt 'com.airbnb.android:paris-processor:2.0.1'
// JUnit Default Dependencies
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
}
【问题讨论】:
-
可能重复 - 只需查看此link。您也可以尝试使缓存无效并重新启动 IDE,然后重建和同步项目。
-
我试过了,但不能解决问题
标签: android android-studio kotlin data-binding