我正在尝试在项目上启用视图绑定,但出现此错误:
无法访问“no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40” 这是一个超类型 'com.kevinabrioux.ping.databinding.ActivityStartingBinding'。查看 您的模块类路径是否缺少或冲突的依赖项
这是我的错误出现的地方:
我在我的 gradle 中激活了视图绑定:
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.kevinabrioux.ping"
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'
}
}
buildFeatures {
viewBinding = true
}
}
就我而言,发生这种情况是因为我在 XML 中粘贴了
<layout>
标记,并且没有使用数据绑定。
删除
<layout>
标签解决了问题。
<?xml version="1.0" encoding="utf-8"?>
<!-- Remove this layout tag and make LinearLayout the root -->
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".viewPresenter.webBrowser.WebBrowserFragment">
.
.
.
</LinearLayout>
</layout>
编辑我的 build.gradle 文件并同步,问题就消失了。认为问题是由于在启用视图绑定的一个分支和禁用视图绑定的另一个分支之间切换 git 中的分支而发生的。