【问题标题】:module classpath for missing or conflicting dependencies for BViewBinding用于 BViewBinding 的缺失或冲突依赖项的模块类路径
【发布时间】:2020-10-09 09:34:17
【问题描述】:

我正在尝试在项目上启用视图绑定,但出现此错误:

无法访问“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
    }
}

【问题讨论】:

  • 你能解决这个问题吗?

标签: android android-viewbinding


【解决方案1】:

发生这种情况是因为我在 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>

【讨论】:

  • 但是,如果去掉布局标签,那我们将如何使用数据绑定呢?
  • @Pushpendra 我没有使用数据绑定,我认为 OP 也不是。如果是的话,我猜你需要添加数据出价依赖项?
  • 如果我们添加依赖项,那么问题就来了,如上所述。删除上述布局后。然后它工作正常。但是给数据绑定错误。特别是在 gradle 版本 7.0.1 中。
  • @Pushpendra 我以前从未使用过数据绑定,但也许this repo 可以帮助您。另请确认 Android 是否支持 gradle 版本 7.0.1。至少在几年前,Android 无法使用最新版本的 gradle。
  • 好的,谢谢@Sufian 的快速回复。正如你分享的上述回购。是的,它在 gradle 版本 4.2.1 中运行良好。但是当我将它升级到最新版本时。它再次停止工作。我不确定,但我认为 android studio 需要调查一下!
猜你喜欢
  • 1970-01-01
  • 2018-10-22
  • 2019-07-01
  • 2023-03-25
  • 2018-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多